Skip to content

Instantly share code, notes, and snippets.

@rajiteh
Created December 30, 2017 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajiteh/82d7d9628dc43de1f22392aaefc6cc3d to your computer and use it in GitHub Desktop.
Save rajiteh/82d7d9628dc43de1f22392aaefc6cc3d to your computer and use it in GitHub Desktop.
meh
#!/bin/bash
## ./script path1 path2
src=$1
dst=$2
function percentage {
jq -n "$(du -s $1 | cut -f1)/$(du -s $2 | cut -f1)*100"
}
cat last_check || :
result_1=$(percentage)
sleep 1
result_2=$(percentage)
touch check_diff
jq -n "$result_2 - $result_1" >> check_diff
avg=$(awk '{s+=$1}END{print (NR?s/NR:"0")}' RS=" " check_diff)
secs=$(jq -n "(100-$result_2)/$avg|floor")
printf 'Completion: %f%%\nETA: %dh:%dm:%ds\n' $result_2 $(($secs/3600)) $(($secs%3600/60)) $(($secs%60)) > last_check
if [ "$(cat check_diff |wc -l)" -gt 50 ]; then
echo "$(tail -25 check_diff)" > check_diff
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment