如何控制提交网格作业时使用的Perl版本?

Dav*_*d B 5 bash grid perl sungridengine perlbrew

我正在使用SGE(Sun Grid Engine)向网格提交作业.我还perlbrew用来管理我安装的Perl版本.我写了一些简短的sh脚本,用于运行perl脚本,需要特定的Perl版本(5.12.2),如下所示:

#!/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
Run Code Online (Sandbox Code Playgroud)

现在,当我提交单个作业时,一切正常,但是当我提交很多时,我开始收到perlbrew相关的错误消息,例如:

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
Run Code Online (Sandbox Code Playgroud)

所以我猜这/home/dave/perl5/perlbrew/bin/perlbrew switch perl-5.12.2条线是造成问题的.

我能做什么?

如何使用perl-5.12.2(默认值为5.8.8)运行脚本?

dra*_*tun 4

我不建议将其放入perlbrew switch perl-5.12.2您运行的任何脚本中。它实际上仅适用于命令行使用。

如果您需要一个脚本来使用特定版本的 Perl,则可以为其提供perlbrewshebang 上的完整路径:

#!/home/dave/perl5/perlbrew/perls/perl-5.12.2/bin/perl

use 5.012;
use warnings;
...
Run Code Online (Sandbox Code Playgroud)

然后确保其可执行并像这样运行:

chmod +x your_perl_program.pl
./your_perl_program.pl
Run Code Online (Sandbox Code Playgroud)

或者在脚本中使用 perl 二进制文件的完整路径名:

#!/bin/bash

/home/dave/perl5/perlbrew/perls/perl-5.12.2/bin/perl your_perl_program.pl
Run Code Online (Sandbox Code Playgroud)


顺便说一句,如果您在脚本或 Perl 程序中运行任何不合格的内容,您将面临潜在的生产和安全问题。例如:

#!/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
Run Code Online (Sandbox Code Playgroud)

前两个不好,因为它会选择第一个perltar在您的路径中找到。因此,这取决于$PATH设置,这可能会成为安全风险。最后一个也不好,因为它依赖于 perlperlbrew当前在运行时切换到的内容:(

因此,这样做可能会成为潜在的生产和安全噩梦。相反,上面应该这样写:

#!/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
Run Code Online (Sandbox Code Playgroud)

希望一切都有意义吗?