开发者

Mysqldump creates empty file when run via cron on linux

I have a bash script mysql_cron.sh that runs mysqldump

#!/bin/bash
/usr/local/mysql/bin/mysqldump -ujoe -ppassword > /tmp/somefile

This works fine. I then call it from cron:

20 * * * * /home/joe/mysql_cron.sh

and this creates the file /tmp/somefile, but the file is always empty. I have tried adding a

source /home/joe/.bash_profile 

to the script to make sure cron has the right env variables, but that doesn't help. I see many other people having this problem but have found no solution. I've also tried the '>' operator in the crontab to cat any cron errors to a file, but that doesn't seem to generate any errors. Any troubleshooting ideas welcomed.开发者_开发问答 Thanks!


Add output of error information to file (as Damp has said), so that you can check if there is any error:

#!/bin/bash
/usr/local/mysql/bin/mysqldump -ujoe -ppassword > /tmp/somefile 2>&1

You can also take a look at MySQL's log files at /var/log in case there is some hint there.


Add this line to your script and compare the result between running it from cron versus running it directly:

env > /tmp/env.$$.out

The $$ will be replaced in the resulting filename by the PID of the parent process (cron or the shell). You should be able to diff the two files and see if anything significant is different between the two environments.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜