LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-05-2004, 10:03 PM   #1
james_cwy
Member
 
Registered: Nov 2003
Posts: 52

Rep: Reputation: 15
Using date as part of logfile name


I would like to write a shell script but am quite new to it. Not sure how to start.

Using the shell script, I hope to run tcpdump and save / log tcpdump's output into a file that the current date is included in the file name.

Eg today is 060504. When I run tcpdump via the shell script, I would like it to direct its output to a file say tcpdumplog060504 - something like that. Then say for the next day, if I run it again, it will log to tcpdumplog070504. So on and so forth.

How can I do this? Hope someone can help me out and provide some guidance.

I am planning to use cron to run the shell script.

Thanks a million.
James
 
Old 05-05-2004, 10:19 PM   #2
Demonbane
LQ Guru
 
Registered: Aug 2003
Location: Sydney, Australia
Distribution: Gentoo
Posts: 1,796

Rep: Reputation: 47
Redirect it to something like "tcpdumplog`date +%d%m%y`"
Code:
tcpdump -options > "/var/log/tcpdumplog`date +%d%m%y`"
 
Old 05-05-2004, 10:21 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
I'd suggest yyyy-mm-dd-tcpdump to have a logical
order by timestamps ;)
 
Old 05-05-2004, 10:27 PM   #4
james_cwy
Member
 
Registered: Nov 2003
Posts: 52

Original Poster
Rep: Reputation: 15
using yyyy-mm-dd-tcpdump ?

Thanks for the help. Really appreciate it.

Tinkster, how can I code using yyyy-mm-dd-tcpdump?
I am new at this so hope you can provide an example.

Thanks again.
James
 
Old 05-05-2004, 10:42 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Almost the same as demonane's...

tcpdump -options > "/var/log/`date +%Y%m%d`-tcpdumplog"



Cheers,
Tink
 
Old 05-05-2004, 11:01 PM   #6
james_cwy
Member
 
Registered: Nov 2003
Posts: 52

Original Poster
Rep: Reputation: 15
Log to text file

I would like the log files to have the txt extension so I can view it.

How would I go about this?

Thanks
James
 
Old 05-06-2004, 01:58 AM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Code:
tcpdump -options > "/var/log/`date +%Y%m%d`-tcpdumplog.txt"


Cheers,
Tink
 
Old 05-06-2004, 02:08 AM   #8
james_cwy
Member
 
Registered: Nov 2003
Posts: 52

Original Poster
Rep: Reputation: 15
Thanks

THanks for all the help.

Appreciate it.
James
 
  


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
Shell scripting: Print output to logfile, error to logfile & screen stefanlasiewski Programming 18 05-22-2008 12:47 PM
logfile analyse saavik Linux - Networking 4 03-30-2005 05:14 AM
put date as part of filename box_l Programming 3 07-27-2004 06:17 AM
Startup Logfile Wynand1 Linux - Newbie 1 06-01-2004 06:04 AM
lastlog date does not match system date? jcmj Linux - Networking 6 10-22-2002 12:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:00 PM.

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