Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

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

share|improve this question

marked as duplicate by Jenny D, mdpc, Falcon Momot, Scott Pack, dunxd May 19 '13 at 19:16

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 8 down vote accepted

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.

share|improve this answer
    
thank you for your feedback I have been trying out the following but to cronjob does not execute the bash if I use the following command 0 0 * * * /mysql_backup.sh – fefe Apr 29 '13 at 13:15

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.

share|improve this answer

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