John Mort wrote:
Can anyone recommend a tool to track network uptime? Some work was done on one of my building's network connection and users are reporting that there are intermittent outages. I'd like some way of pinging a location once a second or minute or so and tracking that over a long period of time like a few days or a week to see if there are any patterns to the outages and how long/often they are occurring.

My simple-minded solution evolved into the following bash script. I start it manually as an ordinary user with "nice -19 scriptname &". It only logs anything if 'ping' has returned nonzero. When it does log anything, it also logs a couple of other things that may or not be related. Modify it however you want, especially the "sleep 15s" at the end. If you come up with any improvements, would you be able to post them here? Be sure to make LOGFILE writable by the user running the script.

#!/bin/bash
LOGFILE=/mnt/vm/$(basename $0).log
TEMPFILE=~/tmp/$(basename $0).tmp
while true ; do
        /bin/ping -c 2 -w 8 206.46.230.44 > "$TEMPFILE"
        RC=$?
        if [ $RC -ne 0 ] ; then
                date >> "$LOGFILE"
                cat "$TEMPFILE" >> "$LOGFILE"
                echo >> "$LOGFILE"
                echo \"ping\" return code: $RC >> "$LOGFILE"
                /sbin/arp -a >> "$LOGFILE"
echo "router reports:" $(wget -qO - http://dslrouter/indexHiddenVZ.htm | grep -E 'ipaddress.*[[:digit:]].*;') >> "$LOGFILE" echo "icanhazip.com reports IP = $(wget -qO - icanhazip.com)" >> "$LOGFILE"
# latest time, in case preceding two lines took a while to time out
                date >> "$LOGFILE"
echo '========================================' >> "$LOGFILE"
        fi
        sleep 15s
done

I also have a similar script that does a 'traceroute' once a minute but only logs it if the output contains a bang or a splat. I also have two tasks in cron.hourly -- one gets the latest system log from my router and appends it to a file, the other uses 'wget' to grab a file from my own website and record the download speed.

Adam

_______________________________________________
Mid-Hudson Valley Linux Users Group                  http://mhvlug.org
http://mhvlug.org/cgi-bin/mailman/listinfo/mhvlug

Upcoming Meetings (6pm - 8pm)                         MHVLS Auditorium
 Jun 1 - Zimbra
 Jul 6 - Jul 2011
 Aug 3 - Scala - 100th MHVLUG meeting

Reply via email to