Skip to content

Instantly share code, notes, and snippets.

@ChengLong
Created April 17, 2014 06:34
Show Gist options
  • Save ChengLong/10958010 to your computer and use it in GitHub Desktop.
Save ChengLong/10958010 to your computer and use it in GitHub Desktop.
Run Ruby Script using cron job

If you see this error when cron job runs a ruby script:

'require': cannot load such file ...

And you are using bundler e.g. require 'bundler/setup'. It's probably because the directory where cron runs the script is not correct, resulting in bundler fails to load gems.

Simply changed the directory to fix it, i.e.

* * * * * /usr/local/bin/ruby -C /home/example/scripts example_script.rb >>/home/example/log/cron.log 2>&1

Note -C will Causes Ruby to switch to the directory..

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