use warnings; use strict; use File::Find; use File::Basename; use Config; use Sys::Hostname; use IPC::Open2; use Switch; #use feature 'say'; my ( $variant, $comp, $patch, $OSinfoSum, $osvers ); my ( @OSinfoSum, @ListInstances ); my $host = hostname; my @ExcludeHosts = qw (monrz testlpar dbssaphad nimsrv consdd gangmon dbssapl04 dbssapl05 batch woeora57x meclcaaq inst conti ksmb01 arch backup -clone -rep); ######################################################################################################## # exclude some hosts from collect ######################################################################################################## if ( $host =~ /monrz|testlpar|dbssaphad|nimsrv|consdd|gangmon|dbssapl04|dbssapl05|batch|woeora57x|meclcaaq|inst|conti|ksmb01|arch|backup|-clone|-rep/ ) { exit 0; } ######################################################################################################## # exclude some hosts from collect ###############################:######################################################################### ######################################################################################################## # test the oS ######################################################################################################## $osvers = &OS_Level; my $OSinfo = "$host" . " : " . "$Config{osname}" . " : " . "$osvers"; #print "$OSinfo\n" ; ######################################################################################################### # test the saphostctrl (SAP-System) and use it for Kernel and patchlevel (SID: Instance number : Kernel : Patchlevel ) ######################################################################################################### #@ListInstances = `/usr/sap/hostctrl/exe/saphostctrl -function ListInstances | sed 's/ Inst Info : //'` ; if ( -e "/usr/sap/hostctrl/exe/saphostctrl" ) { @ListInstances = `/usr/sap/hostctrl/exe/saphostctrl -function ListInstances | grep -vE "DAA|DAB" |sed 's/,//g' | awk '{print \$4,":",\$6,":"}'`; chomp(@ListInstances); } else { my $info = $OSinfo . " : : : : :"; push @OSinfoSum, $info; } foreach (@ListInstances) { #print "$_\n"; my $UpperSID = substr( $_, 0, 3 ); my $Instance = substr( $_, 6, 2 ); my $LowerSID = lc $UpperSID; my $sidadm = $LowerSID . "adm"; my $ListInstances = $_; #print "$UpperSID\n"; #print "$LowerSID\n"; #print "$SIDadm\n"; # delete all OS mails &DEL_mail($LowerSID); my $DBhost = &DBhost($UpperSID); #print "$sidadm \n"; my $command = qq( su - $sidadm -c "cat /dev/null > /var/spool/mail/$sidadm" ); my $disp = `su - $sidadm -c "which disp+work " 2>/dev/null`; my $disp_work_error = $?; #print "error disp+work= $disp_work_error \n"; #print "$disp \n"; if ( $? == 0 ) { #print "$disp \n"; #print "$sidadm\n"; #my @SapKernel_Info = `su - $sidadm -c $disp 2>/dev/null`; my $pid = open( PH, " su - $sidadm -c disp+work 2>/dev/null |" ); # or die $!; my @SapKernel_Info; while () { #print "output = $_"; push @SapKernel_Info, $_; } #print join "\n", @SapKernel_Info; foreach (@SapKernel_Info) { if (/kernel make variant/) { $variant = (split)[-1]; } elsif (/compilation mode/) { $comp = (split)[-1]; } elsif (/patch number/) { $patch = (split)[-1]; } } my $info = $OSinfo . " : " . $ListInstances . " " . $variant . " : " . $comp . " : " . $patch . " : " . $DBhost; push @OSinfoSum, $info; undef $variant; undef $comp; undef $patch; } else { my $info = $OSinfo . " : " . $ListInstances . " : : "; push @OSinfoSum, $info; } } ######################################################################################################### # get with saphostctrl DB type , version and patchlevel ######################################################################################################### #my @ListDatabaseSystems = `/usr/sap/hostctrl/exe/saphostctrl -function ListDatabaseSystems | egrep -i "Database name|Instance name" | sed 's/^[ \t]*//'|sed 's/^ +//'` ; #print "\n\n @ListInstances"; print join "\n", @OSinfoSum; print "\n"; #print "\n\n @ListDatabaseSystems"; ######################################################################################################### # get dbhost from /usr/sap//SYS/profile/DEFAULT.PFL ######################################################################################################### sub DBhost { my $file = "/usr/sap/$_[0]/SYS/profile/DEFAULT.PFL"; my $search = 'dbhost'; open my $fh, '<', $file or die "open($file,ro) failed: $!"; my $seen = ' '; my $third = ''; LINE: while ( my $line = <$fh> ) { # skip lines without search string next LINE if index( lc($line), lc($search), 0 ) < 0; # extract the third field of line $third = ( split( ' ', $line, ) )[2] // ''; if ($third) { last } # keep the fields uniq #$third unless $third eq $seen; #$seen = $third; } return $third; } ######################################################################################################### # delete OS mails ######################################################################################################### sub DEL_mail { my $sidadm = $_[0] . "adm"; my $command = qq( su - $sidadm -c "cat /dev/null > /var/spool/mail/$sidadm" ); system($command ) == 0 or die "Failed <$command>: $!"; #system ("su - $sidadm -c /" echo //'d *//' | mail -N//""); } ######################################################################################################### # get OS Level ######################################################################################################### sub OS_Level { my $OS_Level; my $osname = $Config{osname}; #print "$osname \n"; switch ($osname) { case "aix" { $OS_Level = `oslevel -r`; } case "linux" { $OS_Level = `cat /etc/issue| awk '{print \$3, \$7, \$8}'| tr "\n" " "| tr -d [:blank:]`; } } #print "$OS_Level \n"; chomp $OS_Level; return $OS_Level; } exit