LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 08-19-2007, 06:21 PM   #1
aaargh486
LQ Newbie
 
Registered: Jun 2007
Location: Huizingen, Belgium
Distribution: Ubuntu 7.04
Posts: 20

Rep: Reputation: 0
Piping tcpdump to awk stutters


When i do this "tcpdump | awk '{ print $1 }'" or "tcpdump -l | awk '{print $1 }', the output stutters, I have to wait a long time and suddenly a lot of outputs pop up, while the normal tcpdump gives me fluent output.
The waiting time is sometimes enormously long, minutes long, and suddenly outputting 1000+ lines.

Is this a problem with tcpdump or with awk?

I hope you can help me, THanks in advance.

PS: My real script is longer, these are just examples.
 
Old 08-19-2007, 08:08 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
iirc, awk waits for an end-of-input signal or end-of-line char before it tries to process stuff.
I could be wrong ...
 
Old 08-20-2007, 10:31 AM   #3
aaargh486
LQ Newbie
 
Registered: Jun 2007
Location: Huizingen, Belgium
Distribution: Ubuntu 7.04
Posts: 20

Original Poster
Rep: Reputation: 0
Any idea how I can make it process line per line?
If that doesn't work, I'll just code it in Perl...
 
Old 08-20-2007, 07:47 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
If you want to do it your way, I think you'd have to decide exactly which char value you want awk to treat as 'end-of-line' and see if you can tell awk to do that.
I hardly use awk, so you need to some research and/or hope one of the awk guys here chips in.
Personally, I do use Perl, so I'd go that route myself.
YMMV
sorry I can't be more helpful.
BTW, do you need to do this in realtime, or could you use the save-to-file option tcpdump has?
 
Old 08-21-2007, 06:53 AM   #5
aaargh486
LQ Newbie
 
Registered: Jun 2007
Location: Huizingen, Belgium
Distribution: Ubuntu 7.04
Posts: 20

Original Poster
Rep: Reputation: 0
Yes it needs to respond INSTANTLY. So I'll go with Perl.
I've never worked with Net::Pcap, but I looks easy as pie.

Thanks anyway, I never liked awk.
 
Old 08-21-2007, 08:50 AM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by aaargh486 View Post
When i do this "tcpdump | awk '{ print $1 }'" or "tcpdump -l | awk '{print $1 }', the output stutters, I have to wait a long time and suddenly a lot of outputs pop up, while the normal tcpdump gives me fluent output.
The waiting time is sometimes enormously long, minutes long, and suddenly outputting 1000+ lines.

Is this a problem with tcpdump or with awk?

I hope you can help me, THanks in advance.

PS: My real script is longer, these are just examples.
what exactly do you want to capture? tcpdump output's column 1 is the date, at least on my system. Do you just want to get the date? if you are looking at tcpdump output, i don't think you just want to get the date, right? you might be better off using tcpdump's extensive filtering options to get what you want.
 
Old 08-22-2007, 05:27 AM   #7
aaargh486
LQ Newbie
 
Registered: Jun 2007
Location: Huizingen, Belgium
Distribution: Ubuntu 7.04
Posts: 20

Original Poster
Rep: Reputation: 0
I was looking for the source and the destination's MAC address and their IP address. Also I needed the sequence number. I filtered out all packets with the ACK packet enabled.

But It doesn't matter I programmed it yesterday in Perl.

http://home.scarlet.be/~umeerts/hijack_rst.pl

Thanks anyway.
 
Old 08-22-2007, 08:56 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
I think you want
or die "..."
instead of
&& die
and instead of
|| die
This last is due to precedence rules: 'or' is preferred to '||' in this context.

Personally, I (and most Perl guys) recommend
#!/usr/bin/perl -w
or
use warnings;
 
  


Reply



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
impossible redirection with awk and tcpdump? jgreg Programming 4 07-03-2007 12:32 PM
xmms stutters but it just won't start pvscvl Linux - Software 1 11-21-2005 01:47 PM
Sound stutters dinkelburt Linux - Hardware 6 03-27-2004 02:23 PM
mplayer stutters gonniff Linux - Software 4 09-23-2003 02:23 AM
keyboard stutters on toshiba trumpetgirl Linux - Laptop and Netbook 3 06-11-2003 10:26 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:15 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration