开发者

Running rake from cron

I have started using the Whenever gem to schedule cron jobs with rai开发者_如何学编程ls.

But sadly rake will not run, I traced the problem to the environment not being loaded.

The whenever gem generates scripts like:

/bin/bash -l -c '....

I managed to get it to work with

/bin/bash -i -c '...

[The change is -i (interactive) instead of -l (login)]

Based on the documents of cron, their syntax is correct. Can anyone give a hint to why it might fail on Ubuntu 10.4 ?

Thanks


As you're using whenever gem, first of all, create a :cron task, which would be something like this:

task :cron => :environment do

    Rake::Task['db:your-development-env'].invoke

end

Then in your config/schedule.rb, setup your time of backup:

set :output, "/tmp/cron_log.log"
every 1.day, at: '1:00 am' do; rake 'cron'; end 

To pass the settings to crontab:

whenever --update-crontab
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜