我编写了一个Perl脚本,作为glite-CREAM中间件的插件。该脚本应该只打印输出,这些输出将被存储并发布在BDII数据库中。该脚本在屏幕上打印我想要的所有变量。其中一个名为@Store_MPICH
,从存储在目录中的配置文件中的另一个变量中获取其值。它不会在BDII数据库中发布,即使我运行脚本时所有输出都打印出来,包括此变量@Store_MPICH
。
@Store_MPICH
的值打印为MPICH
。我想@Store_MPICH
的价值一路消失。我可能需要使用包并导入/导出它,我真的不知道。
我的脚本的输出是:
[root@helena plugin]# ./gokop
dn: GlueSubClusterUniqueID=helena.esc.rl.ac.uk,GlueClusterUniqueID=helena.esc.rl.ac.uk,mds-vo-name=resource,o=grid
GlueHostApplicationSoftwareRunTimeEnvironment: MPICH
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE_1_0
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-ABAQUS
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-ABAQUS_6_9
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-CASTEP
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-CASTEPUTILS
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-CASTEPUTILS_5_5_1
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-CASTEP_5_5_1
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-DLPOLY2
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-DLPOLY2_2_16
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-DLPOLY2_2_20
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-DLPOLY3
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-DLPOLY3_3_06
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-DLPOLY3_3_10
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-GAUSSIAN03
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-GAUSSIAN03_E_01
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-GAUSSIAN09
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-GAUSSIAN09_A_02
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-GAUSSIAN09_B_01
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-GAUSSUTILS03
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-GAUSSUTILS03_C_02
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-GAUSSUTILS09
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-GAUSSUTILS09_A_02
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-IDL
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-IDL_7_0
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-NAMD
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-NAMD_2_6
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-NAMD_2_7b1
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-R
GlueHostApplicationSoftwareRunTimeEnvironment: NGS-UEE-R_2_6_0
整个代码是:
#! /usr/bin/env perl
use warnings;
use IO::File;
use IO::Dir;
use IPC::Open3;
my $Pub_prefix = "NGS-UEE-";
my $Pub_version = "NGS-UEE_1_0";
$Siteinfo_file = "/etc/grid-security/siteinfo/site-info.def";
$Sw_env = "CE_RUNTIMEENV";
$MPICH_tag = "MPICH";
my $UEE_dir = "/usr/ngs";
exit unless -d $UEE_dir;
my @Default_tags = ();
my $Default_tags_file = "$UEE_dir" . "/default-tags";
if (-f $Default_tags_file) {
@Default_tags = map {split /\s+/} (IO::File->new($Default_tags_file)->getlines);
}
$fqdn = $ENV{CE_HOSTNAME} || (qx{/bin/hostname --fqdn} =~ m{(\S+)})[0];
$dn = "GlueSubClusterUniqueID=$fqdn,GlueClusterUniqueID=$fqdn,mds-vo-name=resource,o=grid";
my @tags = sort grep {/^[A-Z0-9]+_?/} (IO::Dir->new($UEE_dir)->read);
@Site_entries = ();
@Store_MPICH = ();
if (-f $Siteinfo_file) {
@Site_entries = (IO::File->new($Siteinfo_file)->getlines);
}
foreach $x (@Site_entries) {
if (index($x, "#") == 0) {next;} # Comments should be skipped
@line = split("=", $x);
chomp(@line);
if ($line[0] =~ /$Sw_env/i) {
chomp $line[1];
@values = split(" ", $line[1]);
chomp(@values);
foreach $y (@values) {
if ($y =~ /$MPICH_tag/i) {
@Store_MPICH = $y;
}
}
}
}
print "dn: $dn\n";
print "GlueHostApplicationSoftwareRunTimeEnvironment: @{Store_MPICH}\n";
print "GlueHostApplicationSoftwareRunTimeEnvironment: ${Pub_version}\n";
for my $t (@Default_tags, @tags) {
print "GlueHostApplicationSoftwareRunTimeEnvironment: ${Pub_prefix}$t\n";
}
print "\n";
感谢任何帮助。
答案 0 :(得分:0)
@Store_MPICH是一个数组,我假设您喜欢将它用作数组。
尝试
push @Store_MPICH, $y;
并且所有匹配的值都将存储在@Store_MPICH中。
但是
print "GlueHostApplicationSoftwareRunTimeEnvironment: @{Store_MPICH}\n";
会失败。将其更改为:
print "GlueHostApplicationSoftwareRunTimeEnvironment:\n";
foreach my $value ( @Store_MPICH ) {
print " $value\n";
}
HTH dromedaryrider