Cron runs my script but script doesn't do anything, something to do with mail error??? "got status 0x004b#012" [duplicate]
I have a seriously weird problem with one of the Ubuntu 10.10 web servers I administer.
I wrote a script using ruby and rake to run some tar commands and do a mysqldump of the databases. I've installed an entry in the root users crontab like so:
0 0,12 * * * /bin/bash -l -c 'cd /my/script/path && rake backup:everything'
This is working perfectly on one of the servers. However on the other this doesn't actually seem to execute whats in my script.
I know it's getting called for definite because when I run
grep CRON /var/log/syslog
it returns:
Mar 22 12:00:01 ServerName CRON[10273]: (root) CMD (/bin/bash -l -c 'cd /my/script/path && rake backup:everything')
However it's definitely not doing whats in that script.
When I directly run the script like this:
cd /my/script/path && sudo rake backup:everything
It works perfectly.
Also I did this in the crontab of both servers:
0 0,12 * * * /bin/bash -l -c 'cd /my/script/path && rake backup:everything >> output.txt'
(as in the script I'm doing a "puts 'backing up x folder'" every so often)
On the server where the cron job is working it creates the output.txt file and puts the expected output in there like "Beginning backup" etc.
However on the server where it isn't working it only creates the file but leaves it empty. But when I copy the command from the syslog again and run it manually:
sudo /bin/bash -l -c 'cd /my/script/path && rake backup:everything >> output.txt'
It works fine and the output is as expected.
I may be clutching at straws now but could it be anything to do with this:
CRON[10271]: (root) MAIL (mailed 55 bytes of output but got status 0x004b#012)
This appears in the syslog after every cron call. I only really have this cron job and another small one to update the system clock, but from the looks of it none of them are working correctly.
Is an incorrect mail configuration killing my cron jobs? Is that even possible?
Solution 1:
You should provide the full path to rake in the cron line. Something like:
/sbin/rake
or wherever it actually lives.
If the path that rake lives in isn't in you root user path it won't be able to run.
If it is mail you should see something in the mail log. Check there.
Solution 2:
When you dealing with cron always consider environment variables. You'd better run bash script which imports environment variables (source) and run your command.