Skip to content

ETA time to GETH sync + progress bar #1

@zinqzinq

Description

@zinqzinq

prev_block=0; prev_time=$(date +%s); while true; do
resp=$(curl -s -X POST -H "Content-Type: application/json"
--data '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}'
http://localhost:8545)

current=$(echo "$resp" | jq -r '.result.currentBlock' | sed 's/^0x//')
highest=$(echo "$resp" | jq -r '.result.highestBlock' | sed 's/^0x//')

if [ "$current" = "false" ]; then
echo "[✓] Geth is fully synced!"
break
fi

current_dec=$((16#$current))
highest_dec=$((16#$highest))
percent=$((current_dec * 100 / highest_dec))
now=$(date +%s)
delta=$((now - prev_time))
blocks_done=$((current_dec - prev_block))
[ $delta -gt 0 ] && speed=$((blocks_done / delta)) || speed=0
remaining=$((highest_dec - current_dec))
[ $speed -gt 0 ] && eta_min=$((remaining / speed / 60)) || eta_min=0
eta_h=$((eta_min / 60))
eta_m=$((eta_min % 60))

progress bar

bar_total=25
bar_fill=$((percent * bar_total / 100))
bar_empty=$((bar_total - bar_fill))
progress_bar=$(printf "%0.s█" $(seq 1 $bar_fill))$(printf "%0.s░" $(seq 1 $bar_empty))

echo "📦 [$progress_bar] $percent%% synced | ETA: ${eta_h}h ${eta_m}m"
prev_block=$current_dec
prev_time=$now
sleep 10
done

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions