scheduled task log to a file named after current date
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?
Use date
command:
touch `date +%Y%m%d`
$> 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.
精彩评论