Skip to content

Instantly share code, notes, and snippets.

@marjamis
Last active September 24, 2022 04:23
Show Gist options
  • Save marjamis/dbcdea1380c242d43cf5b56563d1058d to your computer and use it in GitHub Desktop.
Save marjamis/dbcdea1380c242d43cf5b56563d1058d to your computer and use it in GitHub Desktop.
Bash scripts and examples
#!/bin/sh
SHA256SUMS_FILE="./sha256_sums"
UNIQ_COUNTS_SORTED="./uniq_counts_sorted"
find . -type f -exec sha256sum {} \; > $SHA256SUMS_FILE
cat $SHA256SUMS_FILE | sort -k1 | cut -f1 -d\ | uniq -c | sed "s:^ *::g" | sort -rk1 > $UNIQ_COUNTS_SORTED
IFS="
"
for i in $(cat $UNIQ_COUNTS_SORTED) ; do
count=$(echo $i | cut -f1 -d\ )
sha=$(echo $i | cut -f2 -d\ )
if [ "$count" -gt 1 ] ; then
echo "## Duplicate sum: $sha"
grep --color=never $sha $SHA256SUMS_FILE
echo
fi
done > duplicates
#!/bin/bash
function wait_for_completion {
while [ `ps -ef | grep -i $0 | grep -v grep | wc -l` -gt 2 ] ; do
echo "DEBUG CHECK: `ps -ef | grep -i $0 | grep -v grep | wc -l`"
sleep 1
done
echo "DEBUG END: `ps -ef | grep -i $0 | grep -v grep | wc -l`"
}
for i in {1..10}; do
val=$(($RANDOM % 10 + 1))
echo "Item: $i with a random of $val"
(
sleep $val
echo "Finished sleeping... for $val"
) &
done
wait_for_completion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment