4

I have added the following crontab job:

sudo crontab -e

enter image description here

58 * * * * ubuntu /home/ubuntu/backup/mysqlbackup.sh
>/home/ubuntu/backup/log/backup.log

I have tried both root and ubuntu users.

When I run the command:

sudo crontab -l

enter image description here

And when I run:

systemctl status cron

enter image description here

But mysqlbackup.sh is not executed. Any idea what is the problem or how can I diagnose what is going wrong?


Note I have added only minutes to test the script

1 Answers1

9
58 * * * * ubuntu /home/ubuntu/backup/mysqlbackup.sh >/home/ubuntu/backup/log/backup.log

This is incorrect format.

The format is described in the crontab file:

  # m h  dom mon dow   command

ubuntu is not a command. Remove it, so the line reads:

  58 * * * *  /home/ubuntu/backup/mysqlbackup.sh >/home/ubuntu/backup/log/backup.log

Systemwide crontab, specified in /etc/crontab has the user field:

These files also have username fields,
# that none of the other crontabs do.
[...]
# m h dom mon dow user  command
vidarlo
  • 22,691
  • Thanks... should I not add the user? – Hooman Bahreini May 21 '19 at 10:34
  • 2
    No, if you want to run it as a specific user, you should add it to that users crontab, e.g. run crontab -e as the user in question. The editor shows you the correct format, complete with examples. – vidarlo May 21 '19 at 10:35
  • 4
    +1 the user field is an extra field that is only used in system-wide crontabs (/etc/crontab and files in /etc/cron.d/) – steeldriver May 21 '19 at 10:40