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.

This question already has an answer here:

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?

share|improve this question

marked as duplicate by Iain, Tom O'Connor May 13 at 14:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

add comment

2 Answers

up vote 5 down vote accepted

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.

share|improve this answer
    
Beautiful.. Thanks, I forgot the server it wasn't working on is used primarily for hosting ruby on rails applications while the other is used for PHP.. so i recently installed ruby and rake in the default locations on the PHP server just for this script and i must have done it differently for rails.. because "which rake" on the rails server returns: /usr/local/bin/rake and on the PHP server returned /usr/bin/rake.. Anyway.. I'm boring you! thanks! –  Daniel Upton Mar 22 '11 at 15:31
    
Glad I could help out! –  Mike Mar 22 '11 at 16:08
add comment

When you dealing with cron always consider environment variables. You'd better run bash script which imports environment variables (source) and run your command.

share|improve this answer
add comment

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