#!/bin/sh echo host="cheltenham" logdir="/var/log/" routerlog1=$logdir"router" # Master - pruned daily by logrotate routerlog=$logdir"routertmp" # Copy erased at end of this script cp --force $routerlog1 $routerlog let parms=$# if [ $parms -gt 0 ] then day=$(date +"%e") let minutelast=$(date +"%M") let hourlast=$(date +"%H") let minutespan=$1 if [ $minutelast -gt $minutespan ] then let minutefirst=$minutelast-$minutespan let hourfirst=$hourlast else let minutefirst=$minutelast+60-$minutespan let hourfirst=$hourlast-1 if [ $hourfirst -lt 0 ] then hourfirst=23 fi fi echo "Checking $minutespan minutes before $hourlast:$minutelast..." echo let total=0 #echo temp entering while loop #echo "Day:" $day "First hour:" $hourfirst "Last hour" $hourlast #echo "First min:" $minutefirst "Last min:" $minutelast "Min span:" $minutespan while [ $minutefirst -ne $minutelast ] do if [ $minutefirst -lt 10 ] then minutechar="0$minutefirst" else minutechar=$minutefirst fi if [ $hourfirst -eq 24 ] then let hourfirst=0 fi if [ $hourfirst -lt 10 ] then hourchar="0$hourfirst" else hourchar=$hourfirst fi # echo # echo "$day $hourchar:$minutechar" # echo let subtotal=$(grep -c "$day $hourchar:$minutechar" $routerlog) let total=$total+$subtotal let minutefirst=$minutefirst+1 if [ $minutefirst -eq 60 ] then let minutefirst=0 fi done #echo temp exiting while loop #echo "First min: $minutefirst Subtotal: $subtotal Total: $total" let average=$total/$minutespan echo $total "transactions in $minutespan minutes" echo "An average of $average transactions per minute" # echo # pingstring=$(ping -c 3 gateway | grep "round-trip") # echo "Current ping $pingstring to gateway" # echo else # Bytes since network restart #ifconfig eth0 | grep bytes rxstring=$(ifconfig eth0 | grep bytes | cut --delim="T" --fields=1) txstring=$(ifconfig eth0 | grep bytes | cut --delim=")" --fields=2) rxbytes=$(echo $rxstring | cut --delim=":" --fields=2 --delim=":" \ | cut --delim=" " --fields=1) txbytes=$(echo $txstring | cut --delim=":" --fields=2 --delim=":" \ | cut --delim=" " --fields=1) echo $rxbytes "bytes received," $txbytes "bytes sent since networking restart" let bytes=$rxbytes+$txbytes #echo $bytes "bytes since networking restart" totalout=$(grep -c "@out" $routerlog) totalin=$(grep -c "@in" $routerlog) echo $totalout "outbound requests today," $totalin "inbound requests today" # Count outbound tx during each hour echo echo "Start... Total Outbound and Inbound Today" declare -i minutecount hourcount for hour in \ 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 do let hourcount=$(grep "$hour:[0-9]\{2\}:[0-9]\{2\} $host" \ $routerlog | grep -c "@out") #grep "$hour:[0-9]\{2\}:[0-9]\{2\} $host" $routerlog incount=$(grep "$hour:[0-9]\{2\}:[0-9]\{2\} $host" \ $routerlog | grep -c "@in") let minutecount=$hourcount/60 echo $hour":00..." "out:" $hourcount "in:" $incount \ "out/min:" $minutecount done totalout=$(grep -c "@out" $routerlog) echo "Totals.." $totalout $totalin # Count tx by IP address echo echo "IP Address (Host Name) Total Outbound Today" let octet=1 while [ $octet -lt 256 ] do ip="192.168.168."$octet # Look for an IP followed by a space followed by a digit ipcount=$(grep "$ip [0-9]" $routerlog | grep -c "@out") if [ $ipcount -ne 0 ] # Show only active addresses then hostname=$(gethost $ip name) echo $ip" ("$hostname")" $ipcount fi let octet+=1 # Increment done echo echo "Total all IP's...." $totalout echo date echo fi # Clean up temp file rm --force $routerlog