1

I use Crontab on my user to run a lot of curl scripts, they work fine, 40 of them works.

But the scripts that i have in the root' Crontab, using the commando 'sudo crontab -e', are not running, they stoped working about 1 month ago, and worked fine for over 2 years.

Have tried to talk to server people, and none of them have any idea what could be wrong. BTW i'm not a server expert, i can follow a guide, but thats it :)

I have tried: restarting the cron service, "installing new crontab", running the scripts in the normal crontab using the root user, restarting the server, deleting everything in the file, deleting MAILTO.

All scripts works by just running them manually.

this is the fine that isn't working:

MAILTO=""

2 3 * * * "/usr/local/scripts/backup-mysql.sh"
25 3 * * * "/usr/local/scripts/backup-prestashop.sh"
4
  • Try using sudo crontab -u root -e. It's better to specify the user which the crontab is to be used for.
    – Stormlord
    Nov 8 '17 at 21:21
  • Thanks :) tried this and edited the file. but nothing ;(
    – Andersburn
    Nov 8 '17 at 21:59
  • 1.Try to add /usr/local/bin/ to the PATH variable. 2. Better leave MAILTO set to a user because you might also get feedback from cron if an error prevents the execution of your scripts. 3. do it without the "s
    – derHugo
    Nov 8 '17 at 22:12
  • sudo crontab -u root -e ... I was too quick to bash it :-) it worked. I setup a script to send me a mail, and set it to to: * * * * *, but it only ran once a hour' don't know why.
    – Andersburn
    Nov 9 '17 at 8:51
1

The most helpful should be to get errors messages.

2  3  * * *  { date; bash -v "/usr/local/scripts/backup-mysql.sh"; date; }  &>/tmp/cron-backup-mysql.log
25 3  * * *  { date; bash -v "/usr/local/scripts/backup-prestashop.sh"; date; } &>/tmp/cron-backup-prestashop.log

Output is recorded in /tmp/cron-backup-mysql.log and /tmp/cron-backup-prestashop.log. bash -v outputs lines of the script as they are read.

You can check the owner of the file to be sure it run as root. Then read the file, you have the start and end time to check if the run is finished and if the duration is what you expect.

If the script now run correctly, the problem was probably the shell invoked implicitly (remove bash -v from crontab and add echo SHELL = $SHELL to the script) or the execution permission missing on the script (chmod +x).

If the script crash, bash -v will help you to find the bug. You can show more details by replacing -v by -x, but this will flood the output with each expression as they are evaluated.

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.