我编写了一个Rake脚本,应该在Crontab自动运行。当在命令行中输入脚本时,它可以正常运行,但是在Cron中无法正确运行。
该脚本如下所示:
#!/bin/sh
echo `date`
cd /home/mick/myapp/current
rake RAILS_ENV=production mynamespace:myaction
crontab设置看起来像这样:
10 0,6,12,18 * * * /home/mick/work/launch.sh >> /home/mick/work/launch.log
执行后,日志文件中只有日期而没有其他信息,而我在系统日志中收到的错误信息如下:
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)
编辑:
感谢@Holger Just的评论,我找到了这个链接,帮助我得到了一个可用的脚本。
下面是我的脚本的更新版本。
#!/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