Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need some help on perl

Status
Not open for further replies.

subok

MIS
Feb 21, 2005
37
BE

Hi,

I need small help on perl scripting

I have files that is copied on a regular basis and i need to check
the contents to calculate the ratio. depending on the result.
( e.g. .50) it will call another script low.pl
( e.g. .99) it will call another script high.pl

The file is a csv file and come every 5 minutes and I need to calculate the ratio of "OctetsSent" and "OctetsReceived"

HEADER;UtilizationData;10;V16SG; ;0;SCANNER; ;0;MsgSent;MsgReceived;PacketsSent;numPacketsReceived;OctetsSent;OctetsReceived;MsgDiscarded;SentNoCtrl;nReceivedNoCtrl;RetransNoCtrl
UtilizationData;V16SG;2012/07/27;10:45:00;STPSTR01.169;900;FALSE;SCANNER;10;127;2;2055;2112;86428;83432;0;5432;1784;0
UtilizationData;V16SG;2012/07/27;10:45:00;STPSTR01.138;900;FALSE;SCANNER;10;9972;6106;16943;13790;1466256;805508;0;960348;396156;0
UtilizationData;V16SG;2012/07/27;10:45:00;STPSTR01.134;900;FALSE;SCANNER;10;3471;6288;11093;10419;588480;631296;0;254004;316732;0
UtilizationData;V16SG;2012/07/27;10:45:00;STPSTR01.58;900;FALSE;SCANNER;10;20652;23514;39497;29404;4690132;3929776;0;3471992;2947904;0
UtilizationData;V16SG;2012/07/27;10:45:00;STPSTR01.60;900;FALSE;SCANNER;10;20593;19351;36274;26039;4350820;3462084;0;3234956;2593056;0
UtilizationData;V16SG;2012/07/27;10:45:00;STPSTR01.62;900;FALSE;SCANNER;10;24237;21229;40003;28678;5122408;3703840;0;3875508;2746088;0
 
Hi

You can calculate the ratio like this :
Code:
perl -naF';' -e '[b]if[/b][teal]([/teal]$[teal].>[/teal][purple]1[/purple][teal])[/teal][teal]{[/teal][navy]$s[/navy][teal]+=[/teal][navy]$F[/navy][teal][[/teal][purple]13[/purple][teal]];[/teal][navy]$r[/navy][teal]+=[/teal][navy]$F[/navy][teal][[/teal][purple]14[/purple][teal]][/teal][teal]}[/teal]END[teal]{[/teal][b]printf[/b][green][i]"sent %d / received %d / ratio %.6f\n"[/i][/green][teal],[/teal][navy]$s[/navy][teal],[/teal][navy]$r[/navy][teal],[/teal][navy]$r/$s[/navy][teal]}[/teal]' /input/file
Supposing OctetsSent and OctetsReceived will always be the 13th and 14th columns ( counted from 0 ).

Regarding the part with running another script, the simplest way would be like this :
Code:
perl -naF';' -e '[b]if[/b][teal]([/teal]$[teal].>[/teal][purple]1[/purple][teal])[/teal][teal]{[/teal][navy]$s[/navy][teal]+=[/teal][navy]$F[/navy][teal][[/teal][purple]13[/purple][teal]];[/teal][navy]$r[/navy][teal]+=[/teal][navy]$F[/navy][teal][[/teal][purple]14[/purple][teal]][/teal][teal]}[/teal]END[teal]{[/teal][b]system[/b][navy]$r/$s[/navy][teal]<.[/teal][purple]5[/purple][teal]?[/teal][green][i]"low.pl"[/i][/green][teal]:[/teal][green][i]"high.pl"[/i][/green][teal]}[/teal]' /input/file


Feherke.
[link feherke.github.com/][/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top