开发者

Backup database use crontab with date function [duplicate]

This question already has answers here: Is there a special restriction on commands executed by cron? [duplicate] (2 answers) Closed 4 years ago.

I can use this command

mysql开发者_如何学编程dump -u"root"  myDB| gzip > mydb_`date +%d-%m-%Y`.sql.gz

but when run in crontab

* * * * * mysqldump -u"root"  myDB| gzip > mydb_`date +%d-%m-%Y`.sql.gz

( this error cause by function date, when i remove it , crontab run good )

on ubuntu, it happen this error in log file.

ubuntu CRON[xxxx] (user) CMD(mysqldump -u"root"  myDB| gzip > mydb_`date+)
ubuntu CRON[xxxx] (CRON) error ( grandchild #5353 failed with exit status 2)
ubuntu CRON[xxxx] (CRON) info (no MTA installed, discarding output)


% signs in a crontab command are converted to newlines, and all data after the first % is sent to the command's stdin. Replace each % with \%.

(And you only had 4 time fields: * * * *; you need 5 (you later fixed the question).)


From the man 5 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 newline or % character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the crontab file.

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 "\".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜