views:

134

answers:

2

i have a scheduled task running for every 30 mins in ubuntu. i'm writing the log to a file called sh_tsk.log and using >> so that it doesn't overwrite. But what i want is to separate logs using dates. i.e today's log should be in a file named after today's date and tomorrow's log should be in a file named after tomorrow's date. i know i can use touch keyword to create a file. But what i don't know is how do i create the file using current date?

+1  A: 

Use date command:

touch `date +%Y%m%d`
pingw33n
thank you.. got it. i'm using like this though date +%d%m%Y :P
tony_le_montana
with %Y%m%d you'll get log files sorted in a proper way.
pingw33n
+1  A: 
$> touch `date +%F`.log

You should be getting the file as 2009-11-23.log. Now you can use >> to output to this log file.

peakit