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'm trying to get my crontab to run a few rake tasks for a rails app, but it seems to always exit with the status of 127, in my syslog it look like this:

Jun  7 05:10:01 ip-10-170-122-226 CRON[15664]: (deploy) CMD (cd /home/deploy/apps/dashboard/current && bundle exec rake some:task
Jun  7 05:10:01 ip-10-170-122-226 CRON[15662]: (CRON) error (grandchild #15664 failed with exit status 127)

It seems that 127 is like "command not found error" or something, so I've used the full paths to the bins even so like bundle was /usr/local/bin/bundle, The task runs fine outside of cron just running it in shell.

My crontab is simplily just:

*/10 * * * * cd /home/deploy/apps/dashboard/current && bundle exec rake some:task

Does maybe my crontab need #!/usr/bin or something at the top?


update

To just test it, it does seem to run this just fine:

*/1 * * * *  /usr/bin/touch /home/deploy/cron-test.txt

So that leads me to think its like a PATH varible thing, but I don't know how to get the right path vars in there, any thoughts?

share|improve this question

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

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.

3 Answers 3

up vote 5 down vote accepted

Exit status 127 is set by bash when it can not find the command (see Advanced Bash Scripting). To make the debugging easier, you should put all the stuff in a script. Make sure that the script is executable and starts with the interpreter name and path:

#! /bin/bash
cd /.../ &&  next_command

You should have the crontab line similar to:

*/10 * * * * cd /home/deploy/apps/dashboard/current && /PATH_TO/bundle exec rake some:task

or set the PATH variable in crontab:

PATH=/bin:/usr/bin:/sbin:/usr/sbin:/PATH_TO_bundle
*/10 * * * * cd /home/deploy/apps/dashboard/current && /PATH_TO/bundle exec rake some:task
share|improve this answer
    
crontab commands are executed by /bin/sh or by shell specified in the SHELL variable, so it is OK to use 'cd', shell redirection, variable expansion, conditions etc. in crontabs. –  AlexD Jun 8 '11 at 3:57
    
@AlexD - Thank you for pointing that out. –  Mircea Vutcovici Jun 8 '11 at 4:00

See man 5 crontab how to setup PATH for your cron jobs.

share|improve this answer
3  
We try and avoid pointing people straight to a man page. You should answer the question and point to the man page for further reading. –  Iain Jun 8 '11 at 6:33
    
well, regardless it was my Path vars, I'm not sure if this is the best route to take but what I did was just set copy my PATH var string from my env, and paste it the same to the top of the crontab file, is there a way for it to get pulled in the same as my ENV without having to paste it in? Otherwise if I change my ENV path vars I'll have to make sure my crontab is updated. –  Joseph Silvashy Jun 8 '11 at 20:23

Have a look here: http://ubuntuforums.org/showthread.php?t=1760488 perhaps this will point you in the right direction.

Usually what I do with cron jobs is to create a script file, test the script and then place the script in the cron.

Hope that this helps.

share|improve this answer
1  
Welcome to Server Fault! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. –  Iain Jun 8 '11 at 6:33

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