Calculate packet in/out interval script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calculate packet in/out interval script
# 1  
Old 12-13-2011
Calculate packet in/out interval script

Hello

I'm trying to find interval for packet IN/OUT for a gateway.

log looks like:

Code:
02.12.2011 16.28.29:200 PDU  IN CI:424 TRID:200 ID:N/A EID:N/A EX:N/A PDU:0000001f0000000100000000000000c874746f700074746f70000034010100
02.12.2011 16.28.29:228 PDU  OU CI:424 TRID:200 ID:N/A EID:N/A EX:ACK PDU:000000168000000100000000000000c8000210000134

I 've wrote below script to print out PDU IN/OUT timestamps based on combination of "CID"&"TRID" so I can find if delay took place.


Code:
#!/bin/sh
#get all combination of TRID, CID
nawk -v v=200202 '{if(match($5,v))print $5 " "$6}' $LOG | uniq > $OUTPUT
#find PDU IN,OU that match above combination TRID,CID
while read line 
do
grep -w "`echo $line`" $LOG | nawk -v v="$line" '{
if($4=="IN") printf"%s in: %s ",v,$2;
if($4=="OU") printf"out: %s\n",$2; 
}'
done < $OUTPUT


Output looks as below:


Code:
CI:200202 TRID:273111253 in: 20.30.19:760 out: 20.30.19:775
CI:200202 TRID:273111269 in: 20.30.20:400 out: 20.30.20:402
CI:200202 TRID:273111278 in: 20.30.20:400 out: 20.30.20:415
CI:200202 TRID:273111269 in: 20.30.20:400 out: 20.30.20:402
CI:200202 TRID:273111278 in: 20.30.20:400 out: 20.30.20:415

Is there someway to merge above 2 nawk statement into 1 nawk command.

in other words how can I find a certain field "TRID" and then get all matched rows in one nawk command.

So sorry for long thread description.

Best Regards
# 2  
Old 12-13-2011
Try this:

Code:
nawk -v v=200202 -F '[: ]*' '
  $7==v&&$5=="IN" { I[$9]=$2":"$3}
  $7==v&&$5=="OU" { O[$9]=$2":"$3}
  END {for(t in O) print "CI:"v " TRID:"t " in: "I[t] " out: "O[t] }' infile

# 3  
Old 12-14-2011
Many thanks for reply.

Would you please let me know what would be FS when we type:
Code:
-F '[: ]*' '

Best Regards


Moderator's Comments:
Mod Comment Please use code tags!

Last edited by zaxxon; 12-14-2011 at 10:42 AM.. Reason: code tags, see PM
# 4  
Old 12-14-2011
Quote:
Originally Posted by samer.odeh
Many thanks for reply.

Would you please let me know what would be FS when we type:

-F '[: ]*' '
Best Regards
it means,when fs matches the ':' and/or 'space' repeated as many times then produce(split filelds as that) it
so this can be like these
Code:
':' single colon
' ' single space
'    ' multiple spaces
'::::' multiple colons
'   :: :   :  '  multiple spaces and colons in random places

regards
ygemici
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Packet loss coming with big packet size ping

(5 Replies)
Discussion started by: Vishal_dba
5 Replies

2. Shell Programming and Scripting

Script (ksh) to get data in every 30 mins interval for the given date

Hello, Since I m new to shell, I had a hard time to sought out this problem. I have a log file of a utility which tells that batch files are successful with timestamp. Given below is a part of the log file. 2013/03/07 00:13:50 Apache/1.3.29 (Unix) configured -- resuming normal operations... (12 Replies)
Discussion started by: rpm120
12 Replies

3. Shell Programming and Scripting

Main script triggers second and it has to run at specific interval

Hi Friends, I am newbie to shell programming and I am stuck trying to accomplish following task.We use Bamboo CI which executes script1 passing parameters. This Main script executes script2 as backend process as part of one of it statements. Task of script2 is to essentially check whether a... (0 Replies)
Discussion started by: aditya206
0 Replies

4. Shell Programming and Scripting

How to run a script everyday between 7 and 8 pm with the time interval of 5 minutes?

Hi, Can someone help me in running a cronjob everyday between 7 and 8 pm with the time interval of 5 minutes in between to repeat that script. The script is so small and I need that to run daily between this time. Please if possible provide me the syntax for this logic. Thanks. (4 Replies)
Discussion started by: cya
4 Replies

5. Shell Programming and Scripting

compare the interval of 2 numbers of input2with interval of several numbers of input1

Help plz Does any one have any idea how to compare interval ranges of 2 files. finding 1-4 (1,2,3,4) of input2 in input1 of same key "a" values (5-10, 30-40, 45-60, 80-90, 100-120 ). Obviously 1-4 is not one of the range with in input1 a. so it should give out of range. finding 30-33(31,32,33)... (1 Reply)
Discussion started by: repinementer
1 Replies

6. UNIX for Dummies Questions & Answers

Run script in the background with a time interval

I have a script I want to run in the background, and I have looked it up but I am not exactly sure how to do. First of all to run it in the background do you have to put something in the script or is it just a command when you go to run it. I found this solution to it but once again I am not to... (2 Replies)
Discussion started by: mauler123
2 Replies

7. OS X (Apple)

interval in a launchd script

Hi, i'm planning a to automate my backup with a rsync user deamon in my launchd and let that run every 2 hours. my server contains a lot of video data which can expand rapidly , up to 1TB, in an interval of 2 hours. now i'm wondering what will happen when a rsync is running longer then the... (1 Reply)
Discussion started by: wessel
1 Replies

8. Shell Programming and Scripting

run script 1 minute interval without CronTab

I am using Solaris 9. I wish to run my script every 1 minute inteval. Though i can run it using below entry in crontab. * * * * /export/home/username/script/file_exist_&_run.sh in short above script will check whether a specific file exist in a directory. If it found it will inovke another... (10 Replies)
Discussion started by: thepurple
10 Replies

9. Shell Programming and Scripting

script to run repeatedly after a fixed interval of time

Hi , I am working on the following script . I want this script to run and scan the log file repeatedly after 3 hours. This script will run & scan just for the current date logs and after every 3 hours. Kindly advice what to add in this script for this purpose. #!/bin/sh diff common.log... (3 Replies)
Discussion started by: himvat
3 Replies

10. Shell Programming and Scripting

Shell Script Run Interval to be dynamic

Hi All. I have a script which has to be run periodically. The frequency of its run will be decided by a Database stored value PollRate. e.g. If PollRate value is 300secs, then the script should be executed every 5 minutes, if it's 1500secs, it should execute every 15 minutes. Is there... (5 Replies)
Discussion started by: rahulrathod
5 Replies
Login or Register to Ask a Question