3

My bash file is not executed by cronjob created as root. The cronjob setup looks as it follows

0 0 * * * mysql_backup.sh

does need to be decalared with the bash command 0 0 * * * bash mysql_backup.sh ? if I execute manually my bash script manually sudo bash mysql_backup.sh than it's working.

I have been creating the cronjob using sudo crontab u root -e and the bash file is in the root of centos

fefe
  • 367

2 Answers2

10

First, you need to use full path like:

0 0 * * * /path/to/mysql_backup.sh

Second, you need to make sure your script has execute permission or you can invoke it using:

0 0 * * * /bin/bash /path/to/mysql_backup.sh

Third, you need to make sure you are executing your cron job with enough privilege.

Khaled
  • 37,789
0

also, you could add the following command in the first line of your script:

#!/bin/bash

(assuming bash is located in /bin/bash). This will make your script run by bash even when called directly, and not as a parameter of the bash.

You could add some logging and also check your crontab log, to see if there is any error that could lead you to the solution.