First, crontab normaly looks like this:
* * * * * /root/mysql.sh
So remove the surplus sh
and put it at the beginning of the script - #!/bin/bash
I suppose (why are you referring to sh
instead of bash
?) and don't forget to have an execute permission on the file (chmod +x /root/mysql.sh
)
Second, running scripts within crontab is tricky, because the environment is different! You have to set it manually. We start with PATH: go to console and do echo $PATH
, and then copy-paste the result into export PATH=<your path>
to your cron script:
mysql.sh:
#!/bin/bash
export PATH=.:/bin:/usr/local/bin:/usr/bin:/opt/bin:/usr/games:./:/sbin:/usr/sbin:/usr/local/sbin
{
cd /root/validate-mysql-status
/root/validate-mysql-status/validate-mysql-status.sh
} >> OUT 2>> ERR
Note that I also redirected all the output to files so that you don't receive emails from cron.
Problem is how to know which other variables (besides PATH
) matter. Try to go through set | less
and try to figure out which variables might be important to set in the cron script too. If there are any MYSQL related variables, you must set them! You may also examine the cron script environment by putting set > cron.env
to the cron script and then diff-ing it against console environment to look for significant differences.