Skip to content

Instantly share code, notes, and snippets.

@Rycieos
Last active December 18, 2020 15:36
Show Gist options
  • Save Rycieos/4fe47ced46ed88b231ce5d53ea623452 to your computer and use it in GitHub Desktop.
Save Rycieos/4fe47ced46ed88b231ce5d53ea623452 to your computer and use it in GitHub Desktop.
Ping flood a remote destination and log the results
#!/bin/bash
date=$(date '+%Y-%m-%dT%H:%M:%S%z')
data=$(ping -nfqc1000 '2606:4700:4700::1111')
IFS=' ' read min avg max mdev <<<"$(printf '%s' "$data" | grep rtt | sed 's|.* = \([0-9.]*\)/\([0-9.]*\)/\([0-9.]*\)/\([0-9.]*\) ms.*|\1 \2 \3 \4|')"
loss=$(printf '%s' "$data" | grep 'packet loss' | sed 's/.*, \([0-9.]*\)\% packet loss.*/\1/')
printf '{"date":"%s","min":%s,"avg":%s,"max":%s,"mdev":%s,"ploss":%s}\n' "$date" "${min:-null}" "${avg:-null}" "${max:-null}" "${mdev:-null}" "${loss:-null}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment