I am using CentOS 6.6.
I am trying to set up a crontab. I made an .sh script which runs perfectly when executed manually.
The command is following:
mysqldump --skip-lock-tables --single-transaction --hex-blob --flush-logs --master-data=2 -u root -p'password' database1 > database2.sql
However, when I tried to set it up in /etc/crontab file, it won't run.
Here are the contents of crontab file.
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
* * * * * root /home/user/public_html/default1.sh
Also, I would like this script to execute in directory
/home/user/public_html
My script is called default1.sh, and I put it in /home/user/public_html directory.
My goal is to execute this command (or now default1.sh script) as a root user in /home/user/public_html every minute.
Answer
There several things you need to check:
- Make sure your script has an appropriate permissions. You need to have an
x
(at least for user) to be executable. - Make sure
mysqldump
is within crontabPATH
. Otherwise, specify absolute path in your script. - I recommend to specify absolute path for output file to confirm whether it is generated successfully or not. Otherwise, you may get confused about file location.
No comments:
Post a Comment