0

I used the following command in crontab to execute these three commands in a a row every week:

0 0 * * 6 docker export dfdf > backup.tar && python gdrive-upload/upload.py -i backup.tar -o $(date +"%Y-%m-%d-%I-%M-%p")-backup.tar -f backup && rm backup.tar

However, syslog shows the following:

Feb 25 17:36:30 xxx cron[3314]: Error: bad hour; while reading crontab for user root  
Feb 25 17:36:30 xxx cron[3314]: (root) ERROR (Syntax error, this crontab file will be ignored)

The problem should be on the second command as I tried with first && third only and works fine.

python gdrive-upload/upload.py -i backup.tar -o backup.tar -f backup

I wonder why the command syntax is wrong (besides the %)? I have tried it in the command line and it works fine.

I am using ubuntu. Previously the crontab does not work so I deleted /etc/environment file.

Any help will be appreciated. Thanks.

  • Why do you think it's wrong? – choroba Feb 25 '21 at 16:32
  • @choroba Feb 25 17:36:30 xxx cron[3314]: Error: bad hour; while reading crontab for user root Feb 25 17:36:30 xxx cron[3314]: (root) ERROR (Syntax error, this crontab file will be ignored) – yyyyyygivemme5 Feb 25 '21 at 16:40
  • 1
    "bad hour" means the syntax of the time field is wrong, but `0` seems pretty OK for an hour. Are you sure you haven't included any non-printing characters? – choroba Feb 25 '21 at 16:49
  • to check for possibly invisible wrong characters you could use `od -c your_crontab_file` – Bodo Feb 25 '21 at 16:51
  • `%` has special meaning in crontab it needs to be escaped. – Barmar Feb 25 '21 at 16:53
  • Many thanks. But the problem seems more than that. I deleted the % symbol but the error msg still appears. – yyyyyygivemme5 Feb 25 '21 at 17:15
  • I guess the problem is on the second command - python gdrive-upload/upload.py -i backup.tar -o $(date +"%Y-%m-%d-%I-%M-%p")-backup.tar -f backup , would too many arg cause problems? – yyyyyygivemme5 Feb 25 '21 at 17:15

0 Answers0