Hi all,
This program 'info.pl' takes 2 different input file format ( file1.txt or
file2.txt) and display information about the Boot and the Boot Processor.
It works file file 'file1.txt' as it get some information on the "BOOT
INFORMATION" but when running it with 'file2.txt' , it only get
information on "BOOT PROCESSOR INFORMATION" but not the "BOOT INFORMATION"
Can someone tell me what's wrong with my &bootInfo subroutine ?
I think the problem might in line 43
while ( $idx <= $#{$data} and $data->[$idx] !~ m/(The current root cell
is)|AutoBoot/)
but I am not sure.
Thanks
J
use strict;
use warnings;
use Tie::File;
sub makeWord {
my $word = shift;
if ($word =~ /[\/ ]/) {
$word =~ s/\/|_/ /g;
$word = join '', map {ucfirst lc} split / /, $word;
$word =~ s/ //g;
}
return $word;
}
sub bootInfo
{
my $section = shift;
my $data = shift;
my $idx = 0;
my $curr_list;
my $curr_tool;
my $name;
my $value;
my ($cell, $current, $preferred, $warnings);
$idx++ while ($idx <= $#{$data} && $data->[$idx] !~ /$section/);
if ($idx >= $#{$data})
{
print ("$0: Section $section does not appear to have any data!\n");
return;
}
$idx++ while ($idx <= $#{$data} && $data->[$idx] !~ /^[- ]+$/);
if ($idx >= $#{$data})
{
ptint ("$0: Section $section is missing its header!\n");
return;
}
$curr_tool = makeWord($section);
while ( $idx <= $#{$data} and $data->[$idx] !~ m/(The current root cell
is)|AutoBoot/)
{
next if $data->[$idx] =~ /^$/;
next if $data->[$idx] =~ /^[- ]+$/;
if ( $data->[$idx] =~ m{\s+
(\d+)\s+ # Cell
(\d+/\d+)\s+ # Current Monarch
(\d+/\d+)\s* # Preferred Monarch
(\S+(?:\s+\S+)*)?\s* # Warnings
$}xms )
{
($cell, $current, $preferred, $warnings) = ($1,$2,$3,$4);
print " $curr_tool=>MonarchInfo\n";
print "\t$curr_tool=>Cell->$cell\n";
print "\t$curr_tool=>CurrentMonarch->$current\n";
print "\t$curr_tool=>PreferredMonarch->$preferred\n";
print "\t$curr_tool=>Warnings->$warnings\n" if ( defined
$warnings);
}
elsif ( $data->[$idx] =~ m{\s+
(\d+/\d+)\s+ # Current Monarch
(\d+/\d+)\s* # Preffered Monarch
(\S+(?:\s+\S+)*)?\s* # Warnings
$}xms )
{
($current, $preferred, $warnings) =($1,$2,$3);
print " $curr_tool=>MonarchInfo\n";
print "\t$curr_tool=>CurrentMonarch->$current\n";
print "\t$curr_tool=>PreferredMonarch->$preferred\n";
print "\t$curr_tool=>Warnings->$warnings\n" if ( defined
$warnings);
}
elsif ( $data->[$idx] =~ m{\s+
(\d+)\s+ # Current Monarch
(\d+)\s* # Preffered Monarch
(\S+(?:\s+\S+)*)?\s* # Warnings
$}xms )
{
($current, $preferred, $warnings) = ($1,$2,$3);
print " $curr_tool=>MonarchInfo\n";
print "\t$curr_tool=>CurrentMonarch->$current\n";
print "\t$curr_tool=>PreferredMonarch->$preferred\n";
print "\t$curr_tool=>Warnings->$warnings\n" if ( defined
$warnings);
}
else
{
#print ("$0:$section:Line $idx >$data->[$idx]< failed to match
anything INF FILE1\n");
}
}
continue
{
$idx++;
}
while ($idx <= $#{$data} && $data->[$idx] !~ /LAN Address Information:/)
{
if ($idx >= $#{$data})
{
print ("$0: Section $section is missing selftest info!\n");
return;
}
next if $data->[$idx] =~ /^$/;
next if $data->[$idx] =~ /Boottest:$/xms;
next if $data->[$idx] =~ /Boottest\s+Settings/xims;
next if $data->[$idx] =~ /Selftest\s+Setting/xims;
next if $data->[$idx] =~ /^[- ]+$/;
if ($data->[$idx] =~
m/The\s+(current\s+root\s+cell)\s+is\s+(\d+)[.]\s*$/xms )
{
($name,$value) = (makeWord($1), $2);
print " $curr_tool=>RootCellInfo\n";
print "\t$curr_tool=>$name->$value\n";
}
elsif ($data->[$idx] =~
m/The\s+(preferred\s+root\s+cell)\s+is\s+(\d+)[.]\s*$/xms )
{
($name,$value) = (makeWord($1), $2);
print "\t$curr_tool=>$name->$value\n";
}
elsif ($data->[$idx] =~ m/AutoBoot\s*:\s+
(\S+)\s+ # On or off
-\s+Timeout\s+is\s+
(\S+(?:\s+\S+)*)\s* # timeout
$/xms )
{
my $autoboot = $1;
my $timeout = $2;
print " $curr_tool=>AutoBootSettings\n";
print "\t$curr_tool=>AutoBoot->$autoboot\n";
if ($autoboot=~ /ON/i )
{
$timeout =~ m/:\s*(\d+\s+sec)/xms ;
print "\t$curr_tool=>Timeout->$1\n";
}
}
elsif ($data->[$idx] =~ m/\s*
(Os\s+(?:is|is\s+not)\s+
# value
speedy\s+boot\s+aware)[.]\s*
$/xims )
{
my $speedyboot = $1;
}
elsif ($data->[$idx] =~ m/\s*
(\S+)\s+ #Selftest
(\S+(?:\s+\S+)*)\s* # Setting
/xms )
{
my ($selftest, $setting) = (makeWord($1), $2);
print "\t$curr_tool=>$selftest->$setting\n";
}
else
{
print ("$0:$section:Line $idx >$data->[$idx]< doesn't match anything
IN FILE2.\n");
}
}
continue
{
$idx++;
} # end of while
# supposedly at LanAddress section
while ($idx <= $#{$data} && $data->[$idx] !~ /.* INFORMATION/)
{
if ($idx >= $#{$data})
{
print ("$0: Section $section is missing LanInfo data!\n");
return;
}
next if $data->[$idx] =~ /^$/;
next if $data->[$idx] =~ /LAN\s+Address/;
next if $data->[$idx] =~ /^[- ]+$/;
if ( $data->[$idx] =~ /\s*
([*]?) # a * marks the default
Mac[(](\p{IsXDigit}+)[)]\s+ # mac addr
(Acpi\S+(?:\s+\S+)*)\s* # path
/xms )
{
my ($default, $mac, $path) = ($1, $2, $3);
print " $curr_tool=>LanInfo\n";
print "\t$curr_tool=>LanAddress->$mac\n";
print "\t$curr_tool=>Path->$path\n";
print "\t$curr_tool=>Default_LAN->True\n" if ($default);
}
elsif ( $data->[$idx] =~ /\s*
([*]?) # a * marks the default
M\s*\d+\s+Mac[(](\p{IsXDigit}+)[)]\s+ # mac
addr
(Acpi\S+(?:\s+\S+)*)\s* # path
/xms )
{
my ($default, $mac, $path) = ($1, $2, $3);
print " $curr_tool=>LanInfo\n";
print "\t$curr_tool=>LanAddress->$mac\n";
print "\t$curr_tool=>Path->$path\n";
print "\t$curr_tool=>Default_LAN->True\n" if ($default);
}
else
{
print ("$0:$section:Line $idx >$data->[$idx]< doesn't match anything.
in FILE3\n");
}
}
continue
{
$idx++;
}
}
sub bootCpuInfo
{
my $section = shift;
my $data = shift;
my $idx = 0;
my $curr_list;
my $curr_tool;
my $name;
my $value;
my ($cell, $current, $preferred, $warnings);
$idx++ while ($idx <= $#{$data} && $data->[$idx] !~ /$section/);
if ($idx >= $#{$data})
{
print ("$0: Section $section does not appear to have any data!\n");
return;
}
$idx++ while ($idx <= $#{$data} && $data->[$idx] !~ /^[- ]+$/);
if ($idx >= $#{$data})
{
print("$0: Section $section is missing its header!\n");
return;
}
$curr_tool = makeWord($section);
$idx++;
while ( $idx <= $#{$data} and $data->[$idx] !~ m/.*INFORMATION/)
{
next if $data->[$idx] =~ /^$/;
next if $data->[$idx] =~ /^[- ]+$/;
if ( $data->[$idx] =~ m!\s*([-\d]+/\d+/\d+/\d+)! )
{ # Current Monarch
($current) = ($1);
print " $curr_tool=>MonarchInfo\n";
print "\t$curr_tool =>EncBaySocket-> $current \n";
}
else
{
#print ("$0:$section:Line $idx >$data->[$idx]< failed to MAtch
anything\n");
}
}
continue
{
$idx++;
}
}
my $InFileName ;
my @data;
my $idx;
$InFileName = $ARGV[0] || $InFileName;
open(INF, "$InFileName") or die ("Could not open file $InFileName: $!");
close INF;
tie @data, 'Tie::File', $InFileName or die "cannot open $InFileName: $!\n";
if (grep (/
/,@data))
{
chop(@data);
}
my @sectionList = grep {/INFORMATION|DEVICE|CAPABILITIES/} @data;
foreach (@sectionList)
{
print "--$_--\n";
next if ( m/FABRIC\s+INFORMATION\s+is\s+unavailable/);
#warn "Checking section $_\n";
if (m/^\s*BOOT INFORMATION/)
{
bootInfo( $_,\...@data) ;
}
elsif (m/^\s*BOOT PROCESSOR INFORMATION/)
{
bootCpuInfo($_,\...@data) ;
}
else
{
#print "$0:Section >$_< ERR: failed to match anything.\n";
}
}
SYSTEM INFORMATION
Date/Time: May 8, 2009 19:08:15 (20:09:05:08:19:08:15)
Serial Number: USE6482EMN
UUID: 554D7ABC-96EE-11DB-8267-7EF96A3F174C
System Bus Frequency: 266 MHz
BOOT INFORMATION
Monarch CPU:
Current Preferred
Monarch Monarch
CPU CPU
Module/ Module/
Logical Logical Warnings
------- --------- --------
0/0 0/0
AutoBoot: OFF - Timeout is disabled
Boottest:
BOOTTEST Settings Default Variable
Selftest Setting
--------- --------------
early_cpu Run this test
io_hw Run this test
mem_test Run this test
LAN Address Information:
LAN Address Path
----------------- ----------------------------------------
*Mac(0017A4770008) Acpi(HWP0002,PNP0A03,100)/Pci(1|0)/Mac(0017A4770008)
Mac(0017A477000A) Acpi(HWP0002,PNP0A03,100)/Pci(1|1)/Mac(0017A477000A)
FIRMWARE INFORMATION
System Firmware A Revision: 4.11 [4842]
*System Firmware B Revision: 4.21
BOOT INFORMATION
AutoBoot: OFF - Timeout: Disabled - Retries: 0
Boottest:
BOOTTEST Settings Default Variable
OS is not speedy boot aware.
Selftest Setting
--------- --------------
early_cpu Run this test
io_init Skip this test
mem_test Run this test
LAN Address Information:
LAN Address Path
----------------- ----------------------------------------
M 001 Mac(002264FE719E)
AcpiEx(PNP0A08,0x30304352,PNP0A03)/Pci(0x3,0x0)/Pci(0x0,0x0)/MAC(002264FE719E,0x0)
M 002 Mac(002264FE71A2)
AcpiEx(PNP0A08,0x30304352,PNP0A03)/Pci(0x3,0x0)/Pci(0x0,0x1)/MAC(002264FE71A2,0x0)
CPU INFORMATION
Enc/ Active Core
Bay/ Cores/ L3 Family/
CPU Logical Cache Model CPU
Socket CPUs Speed Size (hex.) Rev State
------ ------- -------- ------ ------- --- -------------
-/2/0 2/4 -------- ------ ------- --- Mixed *
-/2/1 2/4 -------- ------ ------- --- Mixed *
CPU threads are turned on.
* CPU socket contains cores with different states.
Use 'info -cores cpu' for more details.
BOOT PROCESSOR INFORMATION
Enc/Bay/
CPU Socket/
Core
-----------
-/2/0
_______________________________________________
Perl-Unix-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs