crontab with mysqldump issue

I'm having an issue with an automatic mysqldump using cron. I have written the following (what I think) is very simple bash script. The database is very small and simple, and I already have automatic backups setup, I am just using this mysqldump as an extra backup.

Code:
#!/usr/local/bin/bash
mysqldump -u username -ppassword database_name > /root/mysql_backup/PIS_Backup

So the issue is, that when I run this bash script everything happens just as normal, a file is created called PIS_Backup. However, when I run it through cron it creates the file, but the file is empty. The cron entry looks like this.

Code:
0 0,12 * * * /root/mysql_backup/backup

Thanks in advance.
 
3. set PATH env variable in crontab. By default PATH is /usr/bin:/bin according to man 5 crontab
 
As mentioned, either set the PATH in the crontab, set the PATH in the script, or use full pathnames in your script.

Alternatively, if it's a single line like that, just put it directly into the crontab.
 
Hi!!

I got the exactly the same problem :(
Can you please explain the exactly details to fix it, please?
It's very important for me
 
Well it is told in the above comments what to do.

first

edit the script so that the script can find mysqldump outside its normal PATH like /usr/bin/ /bin /usr/sbin and /sbin
it would look like the following.
Code:
#!/usr/local/bin/bash
/usr/local/bin/mysqldump -u username -ppassword database_name > /root/mysql_backup/PIS_Backup

or do not call a script and let cron do it all on its own!
It is one command so cron could do it on its own.
Code:
0 0,12 * * * root /usr/local/bin/mysqldump -u username -ppassword database_name > /root/mysql_backup

or make sure cron can find /usr/local/bin

edit the crontab file
If you open the crontab file you will see the following lines
Code:
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin

So add /usr/local/bin to it
Code:
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin

The choice is yours :D

regards
Johan
 
So if i add /usr/local/bin/ in PATH at crontab i don't need the real path of mysqldump and can use MYSQLDUMP=$(which mysqldump) so via which command and that works?
 
Again: leave /etc/crontab alone. It's the system crontab. Use the root crontab (crontab -e) for your own alterations.
 
I will not instruct people any more to alter the /etc/crontab file. :r

Code:
MYSQLDUMP=$(which mysqldump)
if you are using the above, then you cannot ad that in the crontab line.
This is for a script.

Can you post your mysqldump script. (make sure the password is not copied along).

regards
Johan
 
Back
Top