问题
I've run into a weird problem with /usr/bin/env... I designed a simple script to show the problem. The script is in Ruby, but the same happens with a similar script in Python. Here is the script:
#!/usr/bin/env ruby
p ARGV
And another one without /usr/bin/env:
#!/data/software/ruby-1.9.2-p180/bin/ruby
p ARGV
As you see it should just print script arguments. An it works flawlessly on the head node:
[gusev@scyld test]$ which ruby
/data/software/ruby-1.9.2-p180/bin/ruby
[gusev@scyld test]$ ./script.no_usr_bin_env.rb 1 2 3
["1", "2", "3"]
[gusev@scyld test]$ ./script.usr_bin_env.rb 1 2 3
["1", "2", "3"]
But when running on computing node, it gets stuck:
[gusev@scyld test]$ qsub -d $(pwd) -I
qsub: waiting for job 176427.scyld.localdomain to start
qsub: job 176427.scyld.localdomain ready
-bash-3.2$ ./script.no_usr_bin_env.rb 1 2 3
["1", "2", "3"]
-bash-3.2$ ./script.usr_bin_env.rb 1 2 3
<stuck>
/usr/bin/env are exactly the same on both machines:
[gusev@scyld test]$ md5sum /usr/bin/env
7ada476000967f2e4cca2bc669045479 /usr/bin/env
[gusev@scyld test]$ qsub -I -d $(pwd)
qsub: waiting for job 176428.scyld.localdomain to start
qsub: job 176428.scyld.localdomain ready
-bash-3.2$ md5sum /usr/bin/env
7ada476000967f2e4cca2bc669045479 /usr/bin/env
I know that argument processing with /usr/bin/env can be tricky. But we have a lot of software using this and we cannot just fix them all. Is there anything I can do to fix this?
回答1:
#!/usr/bin/env ruby
causes the script to be executed by the first ruby
executable in $PATH
. Your $PATH
could be different on the compute node, most likely because of the way the environment is set up by qsub
.
A quick and dirty fix would be:
PATH=/data/software/ruby-1.9.2-p180/bin:$PATH ./script.usr_bin_env.rb 1 2 3
but you should find a cleaner way to ensure that $PATH
is set correctly before your Ruby scripts are executed.
For more detailed information, try which ruby
or type ruby
and echo $PATH
on the compute node, and make sure that the ruby
command actually works.
(For more discussion on #!/usr/bin/env ...
vs. #!.../ruby
, see my answer to this question).
来源:https://stackoverflow.com/questions/13759588/how-to-fix-usr-bin-env-agrument-processing