Append current date to the filename via Cron?

* * * * * echo "hello" > /tmp/helloFile_$(date +\%Y\%m\%d\%H\%M\%S).txt

You just need to escape the percent signs.

Other date formats: http://www.cyberciti.biz/faq/linux-unix-formatting-dates-for-display/


You must escape the format and use evaluation

mysqldump -u username -pPassword db_name > www/db_backup/db_backup_`date +\%d\%m\%y`.sql

You should use `` instead of '' around the command you want to execute to generate the current date for your filename.


I need to create a new log file every time command is executed. So every day I should have a log like this /home/me/Logs/power_20151230.log The crontab line that I use is this:

00 8 * * * /home/me/power.py ON >> /home/me/Logs/power\_`date +20\%y\%m\%d`

Note the underscore character must be escaped too.

Tags:

Cron

Cron Task