【发布时间】:2015-04-17 15:08:06
【问题描述】:
我遇到一个问题,在进行广泛的谷歌搜索时找不到任何信息。
我有一个通过 crontab 运行的 linux cron,在我尝试将可变日期添加到文件标题之前,它运行良好。但是..当我在 cron 之外运行相同的命令时,只是从命令行,它工作正常。此外,如果我取出日期部分,cron 确实可以工作。
有效的命令行代码:
sudo mysqldump -h mysql.url.com -u user -pPassword intravet sites | gzip > /mnt/disk2/database_`date '+%m-%d-%Y'`.sql.gz
有效的 Cron:
15 2 * * * root mysqldump -h mysql.url.com -u user -pPassword intravet sites | gzip > /mnt/disk2/database.sql.gz
无法正常工作的 Cron:
15 2 * * * root mysqldump -h mysql.url.com -u user -pPassword intravet sites | gzip > /mnt/disk2/database_`date '+%m-%d-%Y'`.sql.gz
我不明白为什么我不能在 cron 中使用日期函数? 我发现的一切都说我可以,但实际上我做不到。
服务器详情: Ubuntu 12.04.5
感谢您提供任何见解。
【问题讨论】:
-
来自手册页:
A "%" character in the command, unless escaped with a backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.