LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-24-2007, 10:07 AM   #16
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241

Code:
#!/bin/sh
awk 'BEGIN{SUBSEP="@"}
 { 
   for (i=1;i<=NF;i++){
      if ($i ~ /SRC/) {
          sub(/^SRC=/,"",$i)
	  ip=$i	  
      }
      else if ($i ~ /DPT/){
          sub(/^DPT=/,"",$i)
	  port=$i
	  array[ip,port]++
      }      
   }
 }
END{
  for ( i in array ){
       n=split(i, s, SUBSEP)
       print s[1] " probed " s[2] " " array[i] " times"
  }
}' "file"
output:
Code:
# ./test1.sh
127.0.0.1 probed 80 1 times
127.0.0.1 probed 984 2 times
10.0.2.15 probed 40390 4 times
10.0.2.15 probed 40414 2 times
127.0.0.1 probed 489 2 times
 
Old 05-24-2007, 10:17 AM   #17
tenaciousbob
LQ Newbie
 
Registered: May 2007
Posts: 11

Original Poster
Rep: Reputation: 0
Thank you thank you thank you!

Works perfectly, and stops me from banging my head against a wall.

Much appreciated!

Im gonna be cheeky now - can i just ask, what does the line 'n=split(i, s, SUBSEP)' do?

Thanks again.

Last edited by tenaciousbob; 05-24-2007 at 10:31 AM.
 
Old 05-24-2007, 10:43 AM   #18
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
Quote:
Originally Posted by tenaciousbob
Thank you thank you thank you!

Works perfectly, and stops me from banging my head against a wall.

Much appreciated!

Im gonna be cheeky now - can i just ask, what does the line 'n=split(i, s, SUBSEP)' do?

Thanks again.
multidimensional arrays are created using concatenation of string indices. therefore if want to store like array[ip,port] , awk will concat to one string using default separater "\034". however i just chose to use "@" for visibility. when we view the array, they are something like this
Code:
array[127.0.0.1@80]
and use ++ to increment the count for identical ip and port. As for the n=split(i, s, SUBSEP) line, i just want to get back the values of ip and port (stored in s), so i can print your desired output. hope you understand.
 
  


Reply

Tags
bash, logs, script, server


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hacked server :( and /var/log/messages el_pajaro! Linux - Security 4 04-17-2006 10:28 PM
Deleted /var/log/messages, can't log any files-iptables chingyenccy Linux - Newbie 7 02-27-2005 04:03 PM
How to log conversation between server in /var/log/messages? juris Linux - Software 1 11-23-2004 09:54 AM
Trigger script by message in /var/log/messages? Zoidy Linux - Software 3 01-17-2004 12:03 AM
iptables, changing log file from /var/log/messages acid2000 Linux - Networking 3 03-11-2003 08:38 PM


All times are GMT -5. The time now is 01:32 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration