Created
July 21, 2011 10:35
-
-
Save arbovm/1096935 to your computer and use it in GitHub Desktop.
oh no! progress monitoring in bash!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
total_percent=3649.39 | |
for i in {0..9}; do | |
last_ten_line_counts[$i]=0 | |
done | |
idx=0 | |
while [ 1 ]; do | |
echo | |
date | |
wc -l log/x* | |
lines=`grep 'key: ' log/x* | wc -l| awk '{ print $1 }'` | |
echo | |
percent=`echo "$lines / $total_percent " | bc -l` | |
echo "$percent %" | |
echo | |
last_ten_line_counts[$idx]=$lines | |
let ten_minutes_ago_idx=($idx+1)%10 | |
if [ "${last_ten_line_counts[$ten_minutes_ago_idx]}" -eq "0" ]; then | |
echo "wait $(( 10 - $idx )) for progress per minute" | |
else | |
per_minute=`echo "(${last_ten_line_counts[$idx]} - ${last_ten_line_counts[$ten_minutes_ago_idx]}) / 10" | bc -l` | |
echo "$per_minute per minute" | |
fi | |
#echo "${last_ten_line_counts[$idx]} - ${last_ten_line_counts[$ten_minutes_ago_idx]}" | |
#echo "idx $idx ten_minutes_ago_idx $ten_minutes_ago_idx" | |
#for i in {0..9}; do | |
# echo ${last_ten_line_counts[$i]} | |
#done | |
(( idx++ )) | |
let idx=$idx%10 | |
sleep 60 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment