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

  • 2
    Add at end of line: 2>&1 This will also redirect stderr to same log file. Then check log for errors. – LeonidMew May 21 at 10:24
  • 1
    To see error messages you can use journalctl -b | grep -i cron – WinEunuuchs2Unix May 21 at 10:37
  • 1
    Please don't add screen dumps of text. Copy and paste text and format it corretly. – Soren A May 21 at 10:49
  • @soren, ok thanks for letting me know. – Hooman Bahreini May 21 at 10:50
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
  • Thanks... should I not add the user? – Hooman Bahreini May 21 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 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 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.