Only with cron: /usr/bin/env: ruby_executable_hooks: No such file or directory

后端 未结 3 836
粉色の甜心
粉色の甜心 2021-01-06 18:01

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

相关标签:
3条回答
  • 2021-01-06 18:25

    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.

    0 讨论(0)
  • 2021-01-06 18:26

    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.

    0 讨论(0)
  • 2021-01-06 18:29

    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

    0 讨论(0)
提交回复
热议问题