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:
#!/bin/bash
/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?
cron runs your command in a restricted environment.section. However I am using absolute paths, and I thought by adding#!/bin/bashit would be able to run the/usr/bin/mysqldumpcommand. – xylar Apr 07 '13 at 17:59sql.gzfile get created at all? As it is now,dumpit.logwill always be empty. If you want to redirect standard error todumpit.logyou need to move2>&1to the end of the line like this:>> /var/backups/dumpit.log 2>&1or simply:2> /var/backups/dumpit.log, sincegzipsends all standard output tomysql_date +%usql.gz. – jaume Apr 07 '13 at 19:24sql.gzdoesn't get created. Do you mean my cron entry should be either:0 1 * * * /var/backups/dumpit.sh >> /var/backups/dumpit.log 2>&1or0 1 * * * /var/backups/dumpit.sh 2> /var/backups/dumpit.log? – xylar Oct 04 '13 at 10:210 1 * * * /var/backups/dumpit.sh 2>> /var/backups/dumpit.loginstead.>>appends standard error to the file. Now/var/backups/dumpit.logshould record any errors and give you a hint of what's going wrong. – jaume Oct 04 '13 at 10:39/bin/sh: /var/backups/dumpit.sh: Permission denied. So I updated permissions fordumpit.shto:-rwxr--r-- 1 root rootwhich worked. – xylar Oct 04 '13 at 11:30