Jimmy
Jimmy

Reputation: 12517

Store cron log in timedate file

I have this code currently:

echo "20 0 * * * cd /var/www/test/ && ./prog >> /var/log/program.log" >> mycron

This works fine, but now I want to store it in a a timedated file each time in the format like this:

program_YYYYMMDD_HHMMSS.log

Can anyone tell me how I can do this? I think I need to use the date variable but im not really sure how to implement it.

Upvotes: 3

Views: 28

Answers (1)

rahul
rahul

Reputation: 304

Yes, you are right. You can use the date variable.

echo "20 0 * * * cd /var/www/test/ && ./prog >> /var/log/program_$(date "+%Y%m%d_%H%M%S").log" >> mycron

Upvotes: 1

Related Questions