in ubuntu server for running a backup.sh file every night at 02:00 AM. I wrote:
00 02 * * * root /home/backup.sh
crontab -l it shows:
00 02 * * * root /home/backup.sh.
I can run backup.sh myself and It works fine.
But it did not work automatically by schedule.
When you run your cron jobs as user jobs (editing jobs with
crontab -e) you don't specify the user. If you run system cron jobs, then you can specify user.
Either put that line to
/etc/cron.d/yourfile using some editor like
Or remove 'root' before /home/backup.sh
Additional note is to make sure that you have all your programs like
mysqldump in your script either with full paths or make sure that they are in your scripts execution environments PATH (which is different from you shells PATH).
man 5 crontab
EXAMPLE CRON FILE
EXAMPLE SYSTEM CRON FILE
Redirect the error messages to a log file and check that.
/home/backup.sh 2>1 /home/backup.output
It's very likely a right or path problem.
There are two points to talk about:
- You don't need to restart the cron daemon when installing a new cron job.
- The most common reasons of failing cron jobs are user privileges/permissions and environment variables. So, you need to make sure you are running the cron job under the same user. Also, try to change the commands used by including the full path.
Here's what comes to my mind:
Are you sure cron daemon is running? Check it.
If it is, is should log all jobs it executes, usually you can find it in /var/log/messages. Check to see if it is really tries to execute this command at that time.
Check cron script permissions.
If so, the problem is probably different environment - jobs executing under cron may have different $PATH (so you need to specify full path to commands in your script). Cron should mail error (and actually any) output of jobs its running. Check /var/mail/root file or setup mail alias root -> yout@email in /etc/aliases.
Try editing crontab in this way :
0 2 * * * root /home/backup.sh
and make sure to give execution permission to the script.
You don't need the 'root' part. That's only for /etc/crontab.
Try this instead:
00 02 * * * /home/backup.sh.
And make sure your crontab has a carriage-return at the end of the line that's supposed to run. This is a known bug in many Cron implementations that prevents the last line of the file from executing.
Better yet, just put a comment at the bottom of your crontab file with a '#' character.