Skip to content

Instantly share code, notes, and snippets.

@narutaro
Last active April 14, 2022 09:26
Show Gist options
  • Save narutaro/bf33b6555cbd9c3f4a24 to your computer and use it in GitHub Desktop.
Save narutaro/bf33b6555cbd9c3f4a24 to your computer and use it in GitHub Desktop.
cron with rbenv

cron does not work with rbenv?

If your cron does not work, in many cases, that's because enviromental value.

Check your environmental values

You use rbenv and created some ruby scripts. Now you want to set it to cron.

43 19 * * * ruby your_ruby_script.rb

Later, you find it does not work while your syslog says that the job itself is propary triggered. Then, it is most likely because of cron environmental value. Probably you miss the environmental value such as path to the right ruby. Check this:

crontab -e

43 19 * * * ruby -v; /home/ubuntu/.rbenv/shims/ruby -v >> /tmp/ruby.type

In my case, the out put is:

cat /tmp/ruby.type
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-linux]

The script was grabbing wrong ruby with wrong set of gems. Correcting the ruby path soleved.

43 19 * * * /home/ubuntu/.rbenv/shims/ruby your_ruby_script.rb

Cheers,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment