DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 7th April 2009
bsdnewbie999 bsdnewbie999 is offline
Package Pilot
 
Join Date: May 2008
Posts: 145
Thanked 0 Times in 0 Posts
Default echo tcpdump date to an output

how to echo the output displayed of command "tcpdump -r /var/log/pflog -o -ttt -vv -e -n" to an output file in shell script?
Reply With Quote
  #2   (View Single Post)  
Old 7th April 2009
DutchDaemon's Avatar
DutchDaemon DutchDaemon is offline
Real Name: Ben
Spam Refugee
 
Join Date: Jul 2008
Location: Rotterdam, The Netherlands
Posts: 337
Thanked 32 Times in 30 Posts
Default

You mean:

tcpdump -r /var/log/pflog -o -ttt -vv -e -n > /var/log/outputfile or
tcpdump -r /var/log/pflog -o -ttt -vv -e -n >> /var/log/outputfile ?

http://www.google.com/search?q=shell+redirection
Reply With Quote
  #3   (View Single Post)  
Old 7th April 2009
jggimi's Avatar
jggimi jggimi is online now
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 3,792
Thanked 214 Times in 189 Posts
Default

Another option is script(1).

Example:

$ script
Script started, output file is typescript
$ sudo tcpdump -r <whatever>
$ ifconfig <whatever>
$ <whatever>
.
.
.
$ exit
Script done, output file is typescript
$ col -b < typescript > session.log.for.today
$ less session.log.for.today
Reply With Quote
  #4   (View Single Post)  
Old 7th April 2009
bsdnewbie999 bsdnewbie999 is offline
Package Pilot
 
Join Date: May 2008
Posts: 145
Thanked 0 Times in 0 Posts
Default

This is my script
Code:
#!/bin/ksh
#

#Reading file
read ANSWER?"Enter location file to read: "

#check source file
if [[ ! -f $ANSWER ]]
then
        print "$ANSWER: File not found or not accessible, make sure your enter t
he right path."
        exit 1
else
        #Name the output file
        read OUTPUT?"Give a name to the output file: "

        #write to file
        echo $(tcpdump -r $ANSWER -o -ttt -vv -e -n) > $OUTPUT
fi

~
when i open the output file, all the data are printed in 1 line...
Reply With Quote
  #5   (View Single Post)  
Old 7th April 2009
bsdnewbie999 bsdnewbie999 is offline
Package Pilot
 
Join Date: May 2008
Posts: 145
Thanked 0 Times in 0 Posts
Default

I think the problem could be the exec command of my previous work.

Code:
exec 0<$ANSWER
How do i make it back to normal?
Reply With Quote
  #6   (View Single Post)  
Old 7th April 2009
anomie's Avatar
anomie anomie is offline
Local
 
Join Date: Apr 2008
Location: Texas
Posts: 446
Thanked 69 Times in 46 Posts
Default

Quote:
Originally Posted by bsdnewbie999
how to echo the output displayed of command "tcpdump -r /var/log/pflog -o -ttt -vv -e -n" to an output file in shell script?
Also see tcpdump(1)'s -w option.
__________________
Kill your t.v.
Reply With Quote
  #7   (View Single Post)  
Old 7th April 2009
IdOp's Avatar
IdOp IdOp is offline
Too dumb for a smartphone
 
Join Date: May 2008
Location: twisting on the daemon's fork(2)
Posts: 572
Thanked 14 Times in 13 Posts
Default

Quote:
Code:
echo $(tcpdump -r $ANSWER -o -ttt -vv -e -n) > $OUTPUT
I believe the echo $( ... ) construct is causing the single line, as the shell is removing any newlines in echo's argument. I'm not sure why you want that construct there, but I'd try removing it entirely. Just keep the command ... you want the standard output from.

Last edited by IdOp; 7th April 2009 at 10:55 PM.
Reply With Quote
  #8   (View Single Post)  
Old 8th April 2009
bsdnewbie999 bsdnewbie999 is offline
Package Pilot
 
Join Date: May 2008
Posts: 145
Thanked 0 Times in 0 Posts
Default

I tried to do it in a sample text file. I use awk to sort the text file and echo to an output file. When i check the output file it doesn't print in new line but in 1 line. I got 3 line of text in the file. Here is my echo .
Code:
echo $(awk '{ print $1 }' $File | sort | uniq -c | sort -nr) > $Output

Last edited by bsdnewbie999; 8th April 2009 at 06:10 AM. Reason: edited
Reply With Quote
  #9   (View Single Post)  
Old 8th April 2009
IdOp's Avatar
IdOp IdOp is offline
Too dumb for a smartphone
 
Join Date: May 2008
Location: twisting on the daemon's fork(2)
Posts: 572
Thanked 14 Times in 13 Posts
Default

@ bsdnewbie999: Sorry if my post seemed too cryptic; maybe it's a language problem.

My suggestion was to replace this

Code:
echo $(tcpdump -r $ANSWER -o -ttt -vv -e -n) > $OUTPUT
with this:


Code:
tcpdump -r $ANSWER -o -ttt -vv -e -n > $OUTPUT
I hope that works for ya.
Reply With Quote
Reply

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
tcpdump package bsdnewbie999 OpenBSD Packages and Ports 6 30th March 2009 05:24 PM
tcpdump snaplen WARNING bsdnewbie999 OpenBSD General 1 17th March 2009 03:24 AM
i would like to know about tcpdump chamnanpol FreeBSD General 8 17th September 2008 11:00 AM
Using Date variable? cwhitmore FreeBSD General 9 13th August 2008 07:16 AM
Help with tcpdump file brokensilence General software and network 2 10th July 2008 03:45 PM


All times are GMT. The time now is 02:48 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick