我现在需要修改perl脚本以使用Failed条目(红色填充)提取表格上方的标题字符串,例如E.2.01.11.03 SETUID & SETGID FILES
和E.2.01.11.05 ORPHAN FILES
。如下图所示,有两个条目:Passed(绿色)和Failed(红色)。我所拥有的perl脚本将使用失败的条目提取列数据,但现在我还需要提取表格上方的标题字符串。
上次我们以这种方式编写每个可能的标题和提取和字符串:
#### SECTION
$hd1= 'E.1';
$hd1a= '1.1.1) Network Settings';
$hd2= 'E.2';
$hd2a= '2.1.1)Protecting Resources – OSRs : Special User ID Administrative Files'; #2.1.1
if ($ReadFile =~ /E.1/) {$main="$hd1";$mainsub1="";};
if ($ReadFile =~ /1.1.1\) Network Settings/) {$mainsub1="- $hd1a";};
if ($ReadFile =~ /E.2/) {$main="$hd2"; $mainsub1="";};
if ($ReadFile =~ /2.1.1\)Protecting Resources – OSRs \: Special User ID Administrative Files/) {$mainsub1="- $hd2a";};
$ServerInfo[5]="$main<br>$mainsub1<br>$mainsub2";
但是我想如果有可能提取字符串,那么可以保存这段代码。
我将在下面发布代码,用于提取失败条目的表格日期:
if ($ReadFile =~ /^PASSED/) {
if ($ReadFile =~ /FOUND FAILED/) {
#print "$ReadFile\n";
$NonCompliantFound++;
#$ServerInfo[2]="@ListIP";
$ServerInfo[2]=(); $ListIP_Cnt=0;for ($i=0;$i<=$#ListIP;$i++){ $ServerInfo[2][$i]="$ListIP[$i]<br>"; $ListIP_Cnt++ ;}
#column I (System Value/Parameter)
$ServerInfo[6]=();
#column J (DBS-IBM Agreed Setting)
$ServerInfo[7]=();
#column K (Current Settings)
$ServerInfo[8]=();
$NC=$MyLineCnt; $NC-=1; #print "==================== $NC\n";
&GetNonCompliant("$NC","On");
} ;
}
sub GetNonCompliant {
$C=shift(@_);
$GetValue=shift(@_);
$cnt1=0;
$cnt2=0;
$cnt3=0;
$cnt4=0;
if ($GetValue eq 'On') {
$xyxycnt=0;
while ($xyxycnt < 5){
if ($MyData[$C] =~ /XYZXYZ/) {
$xyxycnt++;
#print "================= $xyxycnt\n";
};
#print "$ReadFile\n";
if ($xyxycnt == 1) {$ServerInfo[9]="$MyData[$C]";};
if ($xyxycnt == 2) {$cnt2++;$ServerInfo[8][$cnt2]="$MyData[$C]";};
if ($xyxycnt == 3) {$cnt3++;$ServerInfo[7][$cnt3]="$MyData[$C]";};
#5: system value
if ($xyxycnt == 5) {$cnt4++;$ServerInfo[6][$cnt4]="$MyData[$C]";};
#print "$MyData[$C] $C\n";
$C--;
if ($xyxycnt == 5) { &WriteRecord ;};
}
$GetValue=Off;
}
} #--- GetNonCompliant
#--------------------------------------------------------------------------
sub WriteRecord { #--- WriteRecord
for ($i=0 ; $i<=$#ServerInfo ; $i++) {
print OUT "$HTMLTAG{$i}\n";
$RecordLine=linetrim($ServerInfo[$i]);
$RecordLine=linetrim4($RecordLine);
if ($RecordLine =~ /</) {
$RecordLine2=linetrim2($RecordLine);
if ($i==2) {for ($r=0 ; $r<=$ListIP_Cnt; $r++) {$ServerInfo[2][$r]=linetrim2($ServerInfo[2][$r]);print OUT "$ServerInfo[2][$r]" ;};
} elsif ($i==7) {for ($r=$cnt3 ; $r>=0; $r--) {$ServerInfo[7][$r]=linetrim2($ServerInfo[7][$r]);print OUT "$ServerInfo[7][$r]" ;};
} elsif ($i==8) {for ($r=$cnt2 ; $r>=0; $r--) {$ServerInfo[8][$r]=linetrim2($ServerInfo[8][$r]);print OUT "$ServerInfo[8][$r]" ;};
} elsif ($i==6) {for ($r=$cnt5 ; $r>=0; $r--) {$ServerInfo[6][$r]=linetrim2($ServerInfo[6][$r]);print OUT "$ServerInfo[6][$r]" ;};
#} elsif ($i==6) {for ($r=$cnt4 ; $r>=0; $r--) {$ServerInfo[6][$r]=linetrim2($ServerInfo[6][$r]);print OUT "$ServerInfo[6][$r]" ;};
#$ServerInfo[5]="$main<br>$mainsub1<br>$mainsub2";
} else {
print OUT "$RecordLine2\n";
#print "$RecordLine2\n";
}
} else {
if ($i==2) {for ($r=0 ; $r<=$ListIP_Cnt; $r++) {print OUT "$ServerInfo[2][$r]" ;};
} elsif ($i==7) {for ($r=$cnt3 ; $r>=0; $r--) {$ServerInfo[7][$r]=linetrim4($ServerInfo[7][$r]);print OUT "$ServerInfo[7][$r]" ;};
} elsif ($i==8) {for ($r=$cnt2 ; $r>=0; $r--) {$ServerInfo[8][$r]=linetrim4($ServerInfo[8][$r]);print OUT "$ServerInfo[8][$r]" ;};
} elsif ($i==6) {for ($r=$cnt4 ; $r>=0; $r--) {$ServerInfo[6][$r]=linetrim4($ServerInfo[6][$r]);print OUT "$ServerInfo[6][$r]" ;};
} else {
print OUT "$RecordLine\n";
print "$RecordLine" if $i==7;
}
}
}
$NonCompliant++;
} #--- WriteRecord
} #--- Mydata
}