Ubuntu: Make a new archive once per minute using “crontab”


I am trying to make a crontab that makes a new .tar file each minute every business day by using the following code:

*/1 * * * 1,2,3,4,5 tar -cf /home/user/Archiv/$(date +"%Y%m%d%H%M").tar /home/user/Textverarbeitung/ -P  

This doesn't work. Why?


cron treats % as newlines. You need to use escape it i.e. use \% to get literal % as used in date.

So you need:

date +"\%Y\%m\%d\%H\%M"   

Or you can use a script and use all the commands in the script and call the script from crontab.

From man 5 crontab:

Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input. There is no way to split a single command line onto multiple lines, like the shell's trailing "\".


Use \% instead of % - cron uses % as a newline.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »