#!/bin/bash # getstats - Every 'n' minutes, grabs netstats values (via crontab). setglobal logfile = '"/Users/taylor/.netstatlog'" # change for your configuration setglobal temp = ""/tmp/getstats.$Pid.tmp"" trap "$[which rm] -f $temp" 0 if test ! -e $logfile { # first time run? touch $logfile } shell { netstat -s -p tcp > $temp # Check your log file the first time this is run: some versions of netstat # report more than one line, which is why the "| head -1" is used here. setglobal sent = $[grep 'packets sent' $temp | cut -d' ' -f1 | sed 's/[^[:digit:]]//g' | head -1] setglobal resent = $[grep 'retransmitted' $temp | cut -d' ' -f1 | sed 's/[^[:digit:]]//g] setglobal received = $[grep 'packets received$' $temp | cut -d' ' -f1 | \ sed 's/[^[:digit:]]//g] setglobal dupacks = $[grep 'duplicate acks' $temp | cut -d' ' -f1 | \ sed 's/[^[:digit:]]//g] setglobal outoforder = $[grep 'out-of-order packets' $temp | cut -d' ' -f1 | \ sed 's/[^[:digit:]]//g] setglobal connectreq = $[grep 'connection requests' $temp | cut -d' ' -f1 | \ sed 's/[^[:digit:]]//g] setglobal connectacc = $[grep 'connection accepts' $temp | cut -d' ' -f1 | \ sed 's/[^[:digit:]]//g] setglobal retmout = $[grep 'retransmit timeouts' $temp | cut -d' ' -f1 | \ sed 's/[^[:digit:]]//g] /bin/echo -n "time=$[date +%s];" /bin/echo -n "snt=$sent;re=$resent;rec=$received;dup=$dupacks;" /bin/echo -n "oo=$outoforder;creq=$connectreq;cacc=$connectacc;" echo "reto=$retmout" } >> $logfile exit 0