Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Subject: Loop Script

Original Message
Name: Hugo
Date: May 9, 2008 at 08:26:19 Pacific
Subject: Loop Script
OS: Sol 9
CPU/Ram: 4GB
Model/Manufacturer: v240
Comment:
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


Report Offensive Message For Removal

Response Number 1
Name: Devaraj (by Fidy)
Date: May 11, 2008 at 22:15:05 Pacific
Subject: Loop Script
Reply: (edit)
You may want to try something like this:

awk 'BEGIN{x1=0;count1=0;x2=0;count2=0}$0 ~ /destination1/ { if ($6 >= 1){x1+=$6;count1+=1}
$0 ~ /destination2/{if ($6 >= 1){x2+=$6;count2+=1}
END{print "Avg for des1 is:,$x1/$count1,"Avg for dest2 :", $x2/$count2}' /tmp/pingresults.txt


cheers,
Devaraj Takhellambam

Regards,
Big Gun


Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Loop Script

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software



Version Tracker Pro
Keep your software current and secure, effortlessly

Click Here for a Free Scan

Driver Agent
Automatically find the latest drivers for your computer.
Click Here for a Free Scan



The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC