Folks,I have a script that ping 40 sites every 5 minutes. The output of it is in this format:
Mylocation,Destination City - Country,transport,(IP Address):,mm-dd-yy hh:mm,avg latency last 2 pingresults, i.e:
Edison,Hong Kong - China,MPLS,(10.10.22.1):,05-09-08 09:00,318
...
...
Edison,location 40, etc.etc.
and repeats again with results of 40 sites for last five minutes.
Edison,Hong Kong - China,MPLS,(10.10.22.1):,05-09-08 09:05,320
The task...
I need to average the averages for each destination every hour, and every day.
I put this and it works, but how do I do it more effinciently without having to create many interim files and several cron jobs? I was thinking of a loop greping for every location, evaluating average is not empty, so when dividing by total entries for each destination result is accurate.
I am having problem writing a loop script.
#!/bin/ksh
cd /tmp
grep destination1 /tmp/pingresults.txt > dest1.txt
nawk -F, '$6 >=1 {print $6 }' dest1.txt | TR=`wc -l`
nawk -F, '$6 >=1 { x=x+$6 } END { print "Avg = " (x/'"$TR"') }' dest1.txt > avgdest1
grep destination2 /tmp/pingresults.txt > dest2.txt
nawk -F, '$6 >=1 {print $6 }' dest2.txt | TR=`wc -l`
nawk -F, '$6 >=1 { x=x+$6 } END { print "Avg = " (x/'"$TR"') }' dest2.txt > avgdest2
...
and so on for other 38 destinations
I am looking to have one entry for each destination with average for last hour, and last 24 hours, it can be in two different files, using same format as original output.
Your suggestions and ideas will be greatly appreciated.
Thanks