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 flawlessl
It's almost certainly an issue with your environment variables. When running something from cron your .bashrc
isn't activated, so environment variables that might set up, like which ruby version you are pointed to and what your PATH
looks like are likely different.
How to fix this will depend on your environment and what tools, if any, you might be using to select your ruby version (rvm, chruby, rbenv, etc...).
You might want to use something like which ruby
to figure out exactly what ruby to execute and use that in your crontab.
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.
I'm not quite sure why this works but if anyone is using RVM on MacOS this worked for me. I am running database backups using a gem called backup
. I had to put the gem inside my app's Gemfile. Not sure why I have to cd to the app directory.
* * * * * source /Users/john/.rvm/environments/ruby-2.7.1; cd /path/to/app && bundle exec backup perform -t mybackup