我使用Sensu在Sensu客户端上运行检查。
我得到这个错误,由于Ruby版本低于2.0:
syntax error, unexpected ',', expecting kEND
字符串
我已经使用RVM安装了Ruby 2.1.8:
rvm use 2.1.8
Using /home/jenkins/.rvm/gems/ruby-2.1.8
型
我怎样才能强迫interperter使用正确的版本?
我尝试了在文件顶部使用shebang(#!
)的各种方法:
#!/home/jenkins/.rvm/gems/ruby-2.1.8 ruby
个
1.“How to set the correct shebang for the needed Ruby version“没有工作=>#!/usr/bin/env rvm 2.0 do ruby
1.在脚本中:
source "/home/jenkins/.rvm/scripts/rvm"
rvm use "2.1.8"
型
还有其他建议吗
edit感谢@mudasobwa,当我用2.1.8从jenkins用户运行它时,它可以工作。
jenkins@chef-production2-backoffice01:~$ rvm use 2.1.8
Using /home/jenkins/.rvm/gems/ruby-2.1.8
jenkins@chef-production2-backoffice01:~$ ruby check_disk_space.rb #works
CheckDisk OK: All disk usage under 85% and inode usage under 85%
jenkins@chef-production2-backoffice01:~$ rvm use 1.8.7
Using /home/jenkins/.rvm/gems/ruby-1.8.7-head
jenkins@chef-production2-backoffice01:~$ ruby check_disk_space.rb #doesn't work even though first row is #!/home/jenkins/.rvm/rubies/ruby-2.1.8/bin/ruby
check_disk_space.rb:32: syntax error, unexpected ':', expecting kEND
short: '-t TYPE[,TYPE]',
^
check_disk_space.rb:32: syntax error, unexpected ',', expecting kEND
型
另一个问题是,运行脚本的程序是sensu客户端,它是由已知用户sensu
ps aux |grep sensu sensu 13148 4.0 0.4 86512 18696 ? Sl 09:38 0:00 /opt/sensu/embedded/bin/ruby /opt/sensu/bin/sensu-client -b -c /etc/sensu/config.json ...
运行的
2条答案
按热度按时间8ljdwjyq1#
您误用了shebang行格式。应该有可执行文件的路径,如
which ruby
返回的。所以,首选的方法是使用这个Ruby作为标准默认值:
字符串
这应该足以使用所选的Ruby版本运行Ruby脚本。如果您要为该特定脚本选择此版本,最简单的方法是在将版本切换为
rvm
后运行which ruby
,并将上面的输出复制粘贴到shebang行:型
现在在shebang中使用它,没有空格:
型
pgky5nke2#
Shebang with rvm:
字符串