Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a crontask which runs at 1am every morning and dumps all databases.

0 1 * * * /var/backups/dumpit.sh 2>&1>> /var/backups/dumpit.log

The dumpit.sh source:

/usr/bin/mysqldump -u user -ppass --all-databases | gzip > /var/backups/mysql_`date +%u`.sql.gz

The script runs okay when executed manually but fails when run via the cron. Nothing is added to the dumpit.log file. Do I need to turn on logging in my .myc.nf file? Is there anything else I could try?

share|improve this question
Work your way through this serverfault.com/questions/449651/…. If that's the full extent of your crontab (or it's the last line) ensure there is a newline at the end of it. –  Iain Apr 7 '13 at 17:46
@Iain, thanks. I have tested the cron and it is working fine. I think it is related to the cron runs your command in a restricted environment. section. However I am using absolute paths, and I thought by adding #!/bin/bash it would be able to run the /usr/bin/mysqldump command. –  xylar Apr 7 '13 at 17:59
Doesn't the sql.gz file get created at all? As it is now, dumpit.log will always be empty. If you want to redirect standard error to dumpit.log you need to move 2>&1 to the end of the line like this: >> /var/backups/dumpit.log 2>&1 or simply: 2> /var/backups/dumpit.log, since gzip sends all standard output to mysql_date +%u`sql.gz`. –  jaume Apr 7 '13 at 19:24
@jaume sql.gz doesn't get created. Do you mean my cron entry should be either: 0 1 * * * /var/backups/dumpit.sh >> /var/backups/dumpit.log 2>&1 or 0 1 * * * /var/backups/dumpit.sh 2> /var/backups/dumpit.log? –  xylar Oct 4 '13 at 10:21
Use 0 1 * * * /var/backups/dumpit.sh 2>> /var/backups/dumpit.log instead. >> appends standard error to the file. Now /var/backups/dumpit.log should record any errors and give you a hint of what's going wrong. –  jaume Oct 4 '13 at 10:39
show 1 more comment

Your Answer


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

Browse other questions tagged or ask your own question.