why #!/usr/bin/env ruby doesn't work in crontab?

后端 未结 3 2063
半阙折子戏
半阙折子戏 2021-01-12 03:40

I have install ruby by rvm (system-wide), and worked correctly via normal console and my rails program is behaving correctly with both rails runner and ap

3条回答
  •  余生分开走
    2021-01-12 04:27

    I had a similar problem. Cron seems to run commands by default without using the PATH settings you would expect for the user (when logging in as that user). In fact it didn't even seem to use any of the default PATH settings (be it in /etc/profile or elsewhere).

    I was able to find the problem using the following commands (the first one is how cron seems to run commands):

    su -c 'printenv PATH' userX

    With output: /usr/local/bin:/usr/bin:/bin:/usr/games

    su -l userX -c 'printenv PATH'

    With output: /opt/ruby-enterprise-1.8.7-2010.02/bin/:/opt/ruby-enterprise-1.8.7-2010.02/bin/:/usr/local/bin:/usr/bin:/bin:/usr/games

    The first command doesn't seem to populate the PATH variable in any way except for the bare system default. In my case I solved it by just adding the necessary (REE) path to: /etc/login.defs, which by default looks as follows:

    /etc/login.defs:103:ENV_PATH PATH=/usr/local/bin:/usr/bin:/bin:/usr/games

提交回复
热议问题