Skip to content

Instantly share code, notes, and snippets.

@henrik242 henrik242/pingstats.sh
Last active Apr 19, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.