Script to Get information from hmc

Perl Script to collect information from HMC


Without login to hmc we can collect the information about the servers that are configured in a hmc
with perl script


please find the below perl script will do above task for us and will keep the information in CSV file

collect - > store in .csv file

#!/usr/bin/perl

my @systems;
my @lpar;
my @memory,$memo;
my @cpu,$cu;
my $Hostname;
my $UID;

print "\n Enter the HMC Host Name :";
$Hostname = <>;
chomp($Hostname);
print "\n Enter the HMC USER ID :";
$UID = <>;
chomp($UID);

@systems = `ssh $UID\@$Hostname lssyscfg -r sys -F name`;
print "$pass";
print "\n one sone";
open(DATA, "> $Hostname");

print DATA "SERVER NAME:SERIAL NUMBER:VIRTUAL COUNT:MEMORY:CPU COUNT:LPARNAMES \n";
print "\n The number of systems in HMC : @systems \n";
foreach $system1 ( @systems )
{
chomp( $system1);
$cmd = 'ssh '.$UID.'@'.$Hostname.' lssyscfg -r lpar -m \\\''.$system1.'\\\' -F name';

print " $cmd \n";

@lpar = `$cmd`;

$cmd = 'ssh '.$UID.'@'.$Hostname.' lssyscfg -r sys -m \\\''.$system1.'\\\' -F serial_num';
$serialnum = `$cmd`;
chomp($serialnum);
print " Serial number : $serialnum \n";

$cmd = 'ssh '.$UID.'@'.$Hostname.' lshwres -m \\\''.$system1.'\\\' -r proc --level sys | cut -d , -f 4';

print " $cmd \n";
$memo = `$cmd`;
chomp( $memo);
@memory = split('=',$memo);

$cmd = 'ssh '.$UID.'@'.$Hostname.' lshwres -m \\\''.$system1.'\\\' -r mem --level sys | cut -d , -f 4';

print " $cmd \n";
$cu = `$cmd`;
@cpu = split( '=',$cu);
chomp($cpu[1]);
chomp($memory[1]);
print " \n The number of LPARS in system $system1: @lpar \n ";
print " The number of CPU's : chomp($cpu[1]) \n";
print " The Memory in the system is :chomp($memory[1]) \n";

$outline="$system1:$serialnum:$#lpar:$cpu[1]:$memory[1]\n";
$str="";
$count=$#lpar;
while ($count>0)
{
chomp($lpar[$count-1]);
$str = $str."$lpar[$count-1],";
$count=$count-1;
}
print DATA "$system1:$serialnum:$#lpar:$cpu[1]:$memory[1]:$str \n";
}
Number of Hits : Hit Counter by Digits

No comments:

Post a Comment

ADD this Info

Bookmark and Share