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?
#!/usr/bin/env rubycauses the script to be executed by the firstrubyexecutable in$PATH. Your$PATHcould be different on the compute node, most likely because of the way the environment is set up byqsub.A quick and dirty fix would be:
but you should find a cleaner way to ensure that
$PATHis set correctly before your Ruby scripts are executed.For more detailed information, try
which rubyortype rubyandecho $PATHon the compute node, and make sure that therubycommand actually works.(For more discussion on
#!/usr/bin/env ...vs.#!.../ruby, see my answer to this question).