problem
I crontab
add a scheduled task as follows to move old logs to the specified directory every day:
1 |
|
Then this scheduled task does not seem to take effect. The following commands are executed separately without error.
Cause tracking
crontab
For the implementation of, Linux will send email to the corresponding user, so you can locate the problem through email. The above task is under the vg user, check the corresponding email /var/spool/mail/vg
, and find the content related to the problematic task as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
The reason for the error is clearly recorded above: it is over after unexpected EOF while looking for matching ``'
reading the error report and knowing that the `command has not been matched. The problem seems strange, because the timed task command is executed separately and there is no problem. Then carefully look at the content of the email.
1 |
|
The displayed command is incomplete, and the plus sign is over. The% and the following part are lost. The reason can be basically located by combining with the error report.% is a special symbol in crontab, which means a new line starts, so the previous command is truncated.
Solution
If the command executed by crontab contains% and needs to be escaped with \, the above example can be successfully executed if it is changed to this:
1 |
|