LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using date as part of logfile name (https://www.linuxquestions.org/questions/linux-newbie-8/using-date-as-part-of-logfile-name-178410/)

james_cwy 05-05-2004 10:03 PM

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

Demonbane 05-05-2004 10:19 PM

Redirect it to something like "tcpdumplog`date +%d%m%y`"
Code:

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

Tinkster 05-05-2004 10:21 PM

I'd suggest yyyy-mm-dd-tcpdump to have a logical
order by timestamps ;)

james_cwy 05-05-2004 10:27 PM

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

Tinkster 05-05-2004 10:42 PM

Almost the same as demonane's...

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



Cheers,
Tink

james_cwy 05-05-2004 11:01 PM

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

Tinkster 05-06-2004 01:58 AM

Code:

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


Cheers,
Tink

james_cwy 05-06-2004 02:08 AM

Thanks
 
THanks for all the help.

Appreciate it.
James


All times are GMT -5. The time now is 07:14 PM.