Skip to content

Instantly share code, notes, and snippets.

@henrik242
Last active April 19, 2016 08:19
Show Gist options
  • Save henrik242/70f0ebeeac56ebfc152f9147559af5c9 to your computer and use it in GitHub Desktop.
Save henrik242/70f0ebeeac56ebfc152f9147559af5c9 to your computer and use it in GitHub Desktop.
A little script to monitor my network connection
#!/bin/bash
# Add to crontab, e.g.:
#
# * * * * * $HOME/cron/pingstats.sh
IP1=84.xx.20.yy
IP2=129.xx.30.yy
IP3=84.xx.64.yy
LOGFILE=$HOME/stats/pingstats-$(date +"%Y-%m-%d").csv
TMPFILE=/tmp/pingresult-$(date +%s)
function doping {
/sbin/ping -t 10 $1 > $TMPFILE
LOSS=$((grep transmitted $TMPFILE || echo NaN) | cut -d\ -f7)
TIME=$((grep stddev $TMPFILE || echo NaN) | cut -d/ -f5)
rm $TMPFILE
echo $LOSS $TIME
}
if [ ! -f $LOGFILE ]; then
echo date time $IP1 avg $IP2 avg $IP3 avg > $LOGFILE
fi
echo $(date +"%Y-%m-%d %H:%M:%S") $(doping $IP1) $(doping $IP2) $(doping $IP3) >> $LOGFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment