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 checked on internet , this might be a common problem, but I dont know how to solve it, all things that they said are not my case...

The cron is running, I checked, still, I have no log files (at least not in var/log) , I am using Debian 6, my .sh works great, I try it manually but in the cron does not work...

here is my cron code (I use crontab -e and later I restart cron service,even if I think its not necessary..)

14 12  * * * /root/mysqldump.sh > /root/MySQLdump.log

the time its just a test I did some minutes ago... when I try it manually the mysqldump.sh works great, but not at the cron... any other idea?

by the way, what does the 2>&1 do??

Thanks in advance

EDIT:

I enable cron log, and now I checked my log file, it is something like this

Feb 11 13:05:01 myserver /USR/SBIN/CRON[5652]: (root) CMD ("/home/dump/sqldump.sh")

but just that, nothing more...

share|improve this question
    
What does the log file show? Do you receive any email output from cron? (add this to your question) –  James O'Gorman Feb 11 '13 at 18:27
    
What user is the crontab setup for? What log files are you looking for? What's the OS? –  mgorven Feb 11 '13 at 18:27
    
Hi, @JamesO'Gorman there are no log files, its weird, I dont know where else find log files for the cron. –  user156355 Feb 11 '13 at 18:57
    
@mgorven I am using Debian 6, I set the cron logged as root. I dont need the log files to be honest, only log file sof the cron to know if was done or not –  user156355 Feb 11 '13 at 18:58
1  
What are "all things that they said are not [your] case", rather than trying to make us guess? :D –  nickgrim Feb 11 '13 at 18:59
show 2 more comments

3 Answers 3

up vote 1 down vote accepted

The usual reason for scripts working as a particular user but failing under cron is because cron runs with a restricted environment, specifically a minimal PATH.

Your script - as well as your crontab entry - needs to refer to other executables/scripts with the full path e.g. use /usr/bin/mysqldump rather than just mysqldump.


EDIT: Based on your comments, you should change your script to something like the following i.e. ensure you use full paths to mysqldump, gzip and date:

#!/bin/bash
DATE=`/bin/date +"db-%d-%m-%Y"`
/usr/bin/mysqldump -u user -ppassword mydb | /bin/gzip > /home/dump/$DATE.sql.gz
share|improve this answer
    
Thanks, I am using /root/mysqldump.sh, its the full path.. works good, If i move to other folder like /var/www and I try execute it from there I can execute it. –  user156355 Feb 11 '13 at 19:12
    
What about the contents of /root/mysqldump.sh? (Also, your log says /home/dump/sqldump.sh) –  nickgrim Feb 11 '13 at 19:13
    
Its empty... but I have other cron to copy files and it does work when I execute it, but again, as cron does not work... –  user156355 Feb 11 '13 at 19:15
1  
I'm confused. You're getting cron to run an empty script, and you're expecting it to do something? –  nickgrim Feb 11 '13 at 19:17
    
sorry, I was editing, the log file is empty... the .sh has something like this mysqldump -u user-ppassword mydb| gzip > /home/dump/date +"db-%d-%m-%Y".sql.gz ... and works great... –  user156355 Feb 11 '13 at 19:22
show 6 more comments

I think its the quoting that is throwing things off try the following

14 12  * * * "/root/mysqldump.sh > /root/MySQLdump.log"

the 2>&1 redirects the std error to std out

share|improve this answer
    
Thanks, I tried with "" but same result... –  user156355 Feb 11 '13 at 19:07
    
Try the following ... create a script with the command that runs. Then call the script from cron without parameters. i.e. /root/cron.sh is executable and contains /root/mysqldump.sh > /root/MySQLdump.log then just call /root/cron.sh from your crontab –  trent Feb 11 '13 at 21:09
add comment

The cron daemon logs to syslog like most services, so you'll find the logs in /var/log/syslog. The log messages for job runs look something like this:

Feb 11 11:09:01 mamma CRON[30555]: (mgorven) CMD (cat /proc/acpi/battery/BAT0/info > /tmp/BAT0-info)
share|improve this answer
    
Thank you, I checked my logs, my cron log now shows this : Feb 11 13:05:01 myserver /USR/SBIN/CRON[5652]: (root) CMD ("/home/dump/sqldump.sh") –  user156355 Feb 11 '13 at 19:12
add comment

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.