James
James

Reputation: 680

Rails task in crontab error

Using lubuntu 12.10, ruby 1.9.3p374(not RVM), Gem 1.8.23, and Rails 3.2.11

I've just recently installed the Whenever gem to create tasks that will run periodically. I created my task which runs every 1 minute and set it to run using:

whenever --update-crontab myproject --set environment=development

This command puts the following entry in my crontab:

* * * * * /bin/bash -l -c 'cd /home/myuser/projects/myproject && script/rails runner -e development '\''FileImporter.execute'\'' >> /home/myuser/projects/myproject/log/cron_log.log 2>&1'

After waiting for some time I see that in my cron_log.log file spammed with the same exception:

/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in 'require: cannot load such file -- bundler/script (LoadError)

However, when I run the following command manually in the terminal everything works just fine:

/bin/bash -l -c 'cd /home/myuser/projects/myproject && script/rails runner -e development '\''FileImporter.execute'\'' >> /home/myuser/projects/myproject/log/cron_log.log 2>&1'

Let me know if any more information is needed, I'm pretty new to the rails/linux world so I may have left some important stuff out.

Upvotes: 0

Views: 265

Answers (1)

James
James

Reputation: 680

Found the answer here on a similar question: why #!/usr/bin/env ruby doesn't work in crontab?

Apparently PATH isn't set when the cron job executing so you have to set it in the crontab.

Running echo $PATH to see what PATH is set to and putting PATH=/my/path/values at the beginning of the crontab file fixes the issue.

Upvotes: 1

Related Questions