Skip to content

Instantly share code, notes, and snippets.

@0xa
Created May 17, 2018 22:59
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 0xa/158a71b47896824535e2eda588f483a8 to your computer and use it in GitHub Desktop.
Save 0xa/158a71b47896824535e2eda588f483a8 to your computer and use it in GitHub Desktop.
#!/bin/sh
total=$1
if [ -z "$total" ]; then
echo "usage:"
echo " $0 <total>"
echo "total:"
echo " echo 'select count(*) from statuses;' | su - postgres -c 'psql DBNAME'"
exit 1
fi
count() { curl -s 'http://127.0.0.1:9200/_stats?pretty' | jq '._all.primaries.docs.count'; }
timestamp() { date +"%s"; }
start=$(count)
start_time=$(timestamp)
sleep 3
while [ true ]; do
count=$(count)
now=$(timestamp)
dt=$((now - start_time))
dv=$((count - start))
rate=$((dv/dt*60))
#rate=$(echo "scale=2; $dv / $dt * 60" | bc)
progress=$((count * 100 / total))
left=$((total - count))
left_min=$((left / rate % 60))
left_h=$((left / rate / 60))
echo "$progress% ($count/$total) (${dt}s avg: $rate/min) (left: ${left_h}h ${left_min}min)"
sleep 5
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment