I have the following cron
job:
* * * * * /home/db_backups/test.sh
which runs fine and is executed every minute. If I check with sudo grep \(CRON\) /var/log/syslog
I get the following:
Jun 23 11:30:01 analytics CRON[9301]: (CRON) info (No MTA installed, discarding output)
However, if I change the executable file to inreadobase_backup.sh
:
* * * * * /home/db_backups/inreadobase_backup.sh
the script is not run - I can see no records in the log. The executable file if run by itself does the job with no error. Here is the content of the file:
sudo mysqldump -h example.com -u username -ppassword dbname | gzip > db.zip
Both executable files have execution permissions given to everyone. Where should I look at to pinpoint the problem?
EDIT
The job runs and creates backups successfuly if I add to sudo crontab -e
the following line:
*/5 * * * * mysqldump -h example.com -u username -ppassword dbname | gzip > db.zip
However, if I move the execution line mysqldump... db.zip
to inreadobase_backup.sh
file and specify it for the job:
*/5 * * * * /home/db_backups/inreadobase_backup.sh
the job doesn't create backups. I don't know how to check if it runs and what error it outputs if any.
If I simply execute /home/db_backups/inreadobase_backup.sh
in command line the backup is created. And the only line the file contains is this:
mysqldump -h example.com -u username -ppassword dbname | gzip > db.zip
I assume you've added this as a crontab of your own user. The problem is that
cron
has no way of authenticating tosudo
so it can't run your command. The simplest way around that is to add the crontab toroot
's account instead:Then, add this line:
There's no need for a script for something so simple so you may as well add the command itself. Either way, you don't want to use
sudo
with it.In response to your edit:
To rule out various possible complications, make
inreadobase_backup.sh
look like this:Then, to capture any errors, redirect the error output of the script to a file by adding
2> file
to yourcron
line:You can then check
/tmp/cron.error
for more details.