Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a shell script to get a MySQL database dump. This script works fine when run manually

#!/bin/sh
fqn=/home/Mysqluser/daily_dumps/bookstore_`date +%Y%m%d_%H%M%S`.sql.gz
mysqldump -u root -h localhost -pmysql#passwd bookstore | gzip > $fqn

But when I include this script to be run in cron job, it doesnt make the backup.

This is what I included in the cron job:

00 00 * * *  /home/Mysqluser/daily_dumps/bin/backup_database.sh

What am I missing here?

share|improve this question

1 Answer 1

It's probably because the environment(s) (type env at prompt to see it) are different.

I had similar problem trying to run a mysql query in cron.daily, I solved it by adding this flag --defaults-file=/root/.my.cnf

It look like mysqldump has a similar flag --defaults-extra-file (needs to be first argument) but if that doesn't work try to to find out what is the difference between your command-line environment and cron environment. Create a cronjob that prints the output of env to a file and compare it to what you get when you run it from your shell.

share|improve this answer
    
I had something similar on running a php script through cron. The cron job was set to run as my user account, but when we delved further, the php being invoked under cron was from a completely different directory and therefore not running under the same php.ini as my interactive user account. –  Fiasco Labs Feb 29 '12 at 8:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.