LinuxQuestions.org
Visit Jeremy's Blog.
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, 11: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, 11: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, 11:21 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
I'd suggest yyyy-mm-dd-tcpdump to have a logical
order by timestamps ;)
 
Old 05-05-2004, 11: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, 11:42 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

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

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



Cheers,
Tink
 
Old 05-06-2004, 12:01 AM   #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, 02:58 AM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

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


Cheers,
Tink
 
Old 05-06-2004, 03: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


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


All times are GMT -5. The time now is 04:38 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration