这是一个逃避变量的问题:
* * * * * /usr/bin/touch /tmp/$(date +\%Y:\%m).log
# ^ ^
对我有用.
来自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.
所以
*/25 * * * * /bin/bash script.sh > "/var/log/$(date +\%Y-\%m-\%d_\%H:\%M).log"
# ^ ^ ^ ^ ^
应该管用.
注意我使用/ bin / bash而不是bash.