How to run a Ruby script using rbenv with cron

后端 未结 5 725
北荒
北荒 2020-12-05 04:23

I\'m trying to run a Ruby script using rbenv with cron. I know that I need to load rbenv in order to have the right Ruby version loaded.

I\'ve tried options like this

5条回答
  •  醉梦人生
    2020-12-05 05:03

    I've found a solution to load rbenv. Either with a loader importing rbenv to the PATH :

    */1 * * * * /bin/bash -c '. $HOME/.rbenv/loader.sh ; cd /data/app/; ruby -v'

    The '.' before '$HOME/.rbenv/loader.sh' is important, it runs the script in the current shell

    Or without loader, which is better :

    */1 * * * * /bin/bash -c 'export PATH="$HOME/.rbenv/bin:$PATH" ; eval "$(rbenv init -)"; cd /data/app/; ruby -v'

提交回复
热议问题