LoginSignup
3
3

More than 5 years have passed since last update.

rbenv 管理下のruby script をcron から実行する (備忘録)

Last updated at Posted at 2015-11-19

rbenv を使っていると、なにもせずに crontab に ruby script_name とするといろいろ文句を言われますね。

とにかく回避

cronからの起動用shellスクリプトを書く。
rbenv / bundler しているアプリケーションが、ディレクトリ ~/application01 にあるとします。

ruby_script.sh
!/bin/sh

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

cd ~/application01
ruby appli01.rb

起動用shellスクリプトなどは、~/bin に置く習慣なので、crontab はこんなふうに。

2 * * * * ~/bin/ruby_script.sh

もっと簡単な方法がある?

のかもしれませんが、とりあえず備忘録、ということで。
以下も読んではいますが、いまいち理解しきれておりません。
cronからbundle exec...はsu -lc ...が一番便利

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3