如何控制提交网格作业时使用的 Perl 版本? [英] How can I control the Perl version used when submitting grid jobs?
问题描述
我正在使用 SGE(Sun Grid Engine)将作业提交到网格.我还使用 perlbrew
来管理我安装的 Perl 版本.我编写了一些简短的 sh
脚本,用于运行需要特定 Perl 版本 (5.12.2) 的 perl 脚本,如下所示:
I'm working with SGE (Sun Grid Engine) to submit jobs to a grid. I also use perlbrew
to manage my installed Perl versions.
I wrote some short sh
scripts that I use to run a perl script which requires a specific Perl version (5.12.2), which look something like this:
#!/bin/bash
#$-S /bin/bash
source /home/dave/.bash_profile
/home/dave/perl5/perlbrew/bin/perlbrew switch perl-5.12.2
/home/dave/scripts/proc_12.pl --in=/home/dave/in/in.store --dir=/home/dave/in/dir2 --params=/home/dave/in/params.p
现在,当我提交单个作业时,一切正常,但是当我提交多个作业时,我开始收到与 perlbrew
相关的错误消息,例如:
Now, when I submit a single job everything works fine, but when I submit many, I start getting perlbrew
related error messages, like:
ln: creating symbolic link `current' to `perl-5.12.2': File exists
ln: creating symbolic link `/home/dave/perl5/perlbrew/bin/cpan' to `/home/dave/perl5/perlbrew/perls/current/bin/cpan': File exists
ln: creating symbolic link `/home/dave/perl5/perlbrew/bin/cpan2dist' to `/home/dave/perl5/perlbrew/perls/current/bin/cpan2dist': File exists
ln: cannot remove `/home/dave/perl5/perlbrew/bin/cpanp': No such file or directory
ln: cannot remove `/home/dave/perl5/perlbrew/bin/enc2xs': No such file or directory
ln: cannot remove `/home/dave/perl5/perlbrew/bin/find2perl': No such file or directory
所以我猜 /home/dave/perl5/perlbrew/bin/perlbrew switch perl-5.12.2
行导致了问题.
So I guess the /home/dave/perl5/perlbrew/bin/perlbrew switch perl-5.12.2
line is causing the problems.
我能做什么?
如何让我的脚本使用 perl-5.12.2(默认为 5.8.8)运行?
How can I make my script run using perl-5.12.2 (the default is 5.8.8)?
推荐答案
我不建议将 perlbrew 开关 perl-5.12.2
放在你运行的任何脚本中.它实际上只用于命令行.
I don't recommend putting the perlbrew switch perl-5.12.2
in any script you run. Its really only for command line usage.
如果您需要一个脚本来使用特定版本的 Perl,那么可以在 shebang 上为其提供完整的 perlbrew
路径:
If you need a script to use a specific version of Perl then either give it the full perlbrew
path on the shebang:
#!/home/dave/perl5/perlbrew/perls/perl-5.12.2/bin/perl
use 5.012;
use warnings;
...
然后确保其可执行并像这样运行:
Then make sure its executable and run like so:
chmod +x your_perl_program.pl
./your_perl_program.pl
或者在脚本中使用 perl 二进制文件的完整路径名:
Or alternatively use the full pathname to the perl binary in your script:
#!/bin/bash
/home/dave/perl5/perlbrew/perls/perl-5.12.2/bin/perl your_perl_program.pl
顺便说一句,如果您在脚本或 perl 程序中运行任何不合格的内容,您将面临潜在的生产和安全问题.例如:
BTW, you will have potential production and security issues if you run anything unqualified in your scripts or perl programs. For eg:
#!/bin/sh
# security risk
perl some_script.pl
# and not just perl
tar cvf archive.tar *.txt
# production risk
/home/dave/perl5/perlbrew/bin/perl some_other_script.pl
前两个不好,因为它会拾取第一个 perl
&tar
它在您的路径中找到.所以这取决于 $PATH
设置,这可能会带来安全风险.最后一个也不好,因为它依赖于 perl perlbrew
当前在运行时切换到的内容:(
The first two are bad because it will pick up the first perl
& tar
it finds in your path. So this depends on $PATH
setting and this could become a security risk. The last is also not good because its reliant on what perl perlbrew
is currently switched to at the point in time its run :(
所以这样做可能是一种潜在的生产方式安全噩梦.相反,上面应该这样写:
So doing this can be a potential production & security nightmare. Instead the above should be written like this:
#!/bin/sh
# fully qualified now. Uses OS provided perl
/usr/bin/perl some_script.pl
# ditto
/usr/bin/tar cvf archive.tar *.txt
# this needs to run in perl 5.12.2
/home/dave/perl5/perlbrew/perls/perl-5.12.2/bin/perl some_other_script.pl
希望这一切都有意义吗?
Hope that all makes sense?
这篇关于如何控制提交网格作业时使用的 Perl 版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!