0

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.

5
  • You don't have an NFS-mounted home directory, by any chance? Commented Jun 1, 2015 at 10:24
  • @MadHatter No, I don't have. Commented Jun 1, 2015 at 10:47
  • OK, then that's not it; just checking. Commented Jun 1, 2015 at 10:49
  • How do you launch it manually? Can you report all steps? And how do you know it won't run? What is the expected result that you don't see? Commented Jun 1, 2015 at 13:31
  • I launch it by changing the directory in terminal, and launching the command afterwards. Commented Jun 2, 2015 at 6:43

2 Answers 2

0

There several things you need to check:

  1. Make sure your script has an appropriate permissions. You need to have an x (at least for user) to be executable.
  2. Make sure mysqldump is within crontab PATH. Otherwise, specify absolute path in your script.
  3. 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.
2
  • Permissions are ok. Mysqldump is listed in /usr/bin, which I have in my crontab. Did you mean that? I will try with absolute path. Commented Jun 1, 2015 at 11:34
  • Finally, it is working with adding absolute path in output file. I solved problem with putting the command directly in crontab file in /etc/crontab. Commented Jun 2, 2015 at 6:44
1

Also, -u root is wrong syntax. Should be -uroot AFAIK.

Anyway, try to log your cron entry by adding

>> /somefile.log 2>&1 

to the cron line

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.