My rocket script launches Rake when run via cron

I wrote a Rake script that should run automatically with Crontab. The script works fine when typing on the command line, but does not work correctly inside cron.

The script looks like this:

#!/bin/sh

echo `date`
cd /home/mick/myapp/current
rake RAILS_ENV=production mynamespace:myaction

The crontab setup looks like this:

10 0,6,12,18 * * * /home/mick/work/launch.sh >> /home/mick/work/launch.log

After execution, the log file just contains a date, but nothing else, and the error I get in syslog looks like this:

Mar 18 18:10:01 CRON[21773]: (mick) CMD (/home/mick/work/launch.sh >> /home/mick/work/launch.log)
Mar 18 18:10:01 CRON[21772]: (CRON) error (grandchild #21773 failed with exit status 127)
Mar 18 18:10:01 postfix/sendmail[21776]: fatal: open /etc/postfix/main.cf: No such file or directory
Mar 18 18:10:01 CRON[21772]: (mick) MAIL (mailed 1 byte of output; but got status 0x004b, #012)

EDIT :

Thanks @Holger Just a comment, I found this link that helped me get a working script.

Here is the updated version of my script

#!/usr/bin/env bash # UPDATED TO GET ACCESS TO 'source'

export PATH=blabla # NOT SURE THIS HELPED AS IT WAS MY FIRST MODIF AND DIDN'T FIX
source /home/mick/.rvm/environments/default # LOADING RVM TO MAKE THINGS WORK
echo `date`
cd /home/mick/myapp/current
rake RAILS_ENV=production mynamespace:myaction
+5
source share
1 answer

Cron $PATH. , $PATH script, . script

export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

, , , $PATH. . , echo $PATH.

, RVM, cron script , cron rvm ( ) .

+4

All Articles