Skip to content

Instantly share code, notes, and snippets.

@Jcpetrucci
Last active October 30, 2015 19:14
Show Gist options
  • Save Jcpetrucci/706949028d015e88e31d to your computer and use it in GitHub Desktop.
Save Jcpetrucci/706949028d015e88e31d to your computer and use it in GitHub Desktop.
Plot ping response times in ASCII graph.
function pingplot {
local destination="$1"
[[ -n $destination ]] || read -rp 'Ping host: ' destination;
results="$(mktemp)";
ping "$destination" | sed -ur 's/^PING.*//;s/.*seq=([0-9]+)/\1/;s/ttl.*time=([0-9]+).*/\1/' > "$results" &
sleep 1 && pidof ping || { echo Something went wrong with the ping.; return 1; }
watch "tail -100 "$results" | gnuplot -e \"set key off; set title 'Pinging: $destination'; set terminal dumb size $((COLUMNS - 5)) 25; plot '/dev/stdin' w lp;\"";
kill %ping
rm "$results"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment