The following script in crontab cannot
0 1 * * * (cd /u01/prod; rsync -avz app 192.168.0.192:/u01/prod/) &>/home/applprod/backuplog/rsync_`date +%Y%m%d_%H%M%S`.log
During execution, the /var/log/messages log displays:
Sep 22 22:50:01 ebsapp CROND[13389]: (applprod) CMD ((cd /u01/prod; rsync -avz app 192.168.0.192:/u01/prod/) &>/home/applprod/backuplog/rsync_`date +)
It seems that the command has been truncated.
So I encapsulated all the commands to be executed into a script and put them in crontab for execution.
But when I checked the crontab manpage later, I found that % has a special meaning in crontab:
The "sixth" field (the rest of the line) specifies the command to be run. The entire command portion of the line, up to a new- line or % character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the cronfile. 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.
The problem is now clear. It is not that the crontab command is truncated, but is understood as There is another meaning, and the solution is to escape %. The modified script becomes:
03 23 * * * (cd /u01/prod; rsync -avz app 192.168.0.192:/u01/prod/) &>/home/applprod/backuplog/rsync_`date +\%Y\%m\%d_\%H\%M\%S`.log