CronJob not running

前端 未结 11 1257
攒了一身酷
攒了一身酷 2020-11-22 02:33

I have set up a cronjob for root user in ubuntu environment as follows by typing crontab -e

  34 11 * * * sh /srv/www/live/CronJobs/daily.sh
  0          


        
11条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 02:39

    Another reason crontab will fail: Special handling of the % character.

    From the man file:

    The entire command portion of the line, up to a newline or a
    "%" character, will be executed by /bin/sh or by the shell specified
    in the SHELL variable of the cronfile.  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.
    

    In my particular case, I was using date --date="7 days ago" "+%Y-%m-%d" to produce parameters to my script, and it was failing silently. I finally found out what was going on when I checked syslog and saw my command was truncated at the % symbol. You need to escape it like this:

    date --date="7 days ago" "+\%Y-\%m-\%d"
    

    See here for more details:

    http://www.ducea.com/2008/11/12/using-the-character-in-crontab-entries/

提交回复
热议问题