I have a perl script that uses system() to call a shell command, which uses ruby_executable_hooks.
When I run this script from the command line it executes flawlessly.
However when it runs from a cron job, I get one of two errors: A) if I do not chdir() ie. working dir is /home/foobar
/usr/bin/env: ruby_executable_hooks: No such file or directory
B) if I chdir( "[doc root]/cgi-bin" )
/usr/lib/ruby/site_ruby/1.8/rubygems.rb:779:in `report_activate_error': Could not find RubyGem twurl (>= 0) (Gem::LoadError)
from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:214:in `activate'
from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:1082:in `gem'
from /home/foobar/.rvm/gems/ruby-1.9.3-p551/bin/twurl:22
from /home/foobar/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/gems/1.9.1/bin/ruby_executable_hooks:15
What might be the reason it cannot find certain files when run from cron?
I found the answer here: https://unix.stackexchange.com/questions/27289/how-can-i-run-a-cron-command-with-existing-environmental-variables
Specifically, I just put ". $HOME/.profile;" in front of the cron command like so:
0 5 * * * . $HOME/.profile; /path/to/command/to/run
Thank you all for putting me on the right track.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With