File: //opt/perf/bin/watchhpcs.pl
#!/opt/OV/nonOV/perl/a/bin/perl -w
use strict;
use warnings;
my $OS = `uname`;
chomp($OS);
my $hpcsbin = "";
my $oalicense = "";
if ( $OS eq "AIX" ) {
$hpcsbin = "/usr/lpp/OV/bin/ovc -start hpsensor";
$oalicense = "/usr/lpp/OV/bin/oalicense -check";
}
else {
$hpcsbin = "/opt/OV/bin/ovc -start hpsensor";
$oalicense = "/opt/OV/bin/oalicense -check";
}
my $licenseCheckRTMA = $oalicense." RTMA";
my $licenseCheckGP = $oalicense." GP";
my $RTMACheck = `$licenseCheckRTMA`;
my $GPCheck = `$licenseCheckGP`;
my $datestring = "";
my $fh;
my $hpcswatch = "/var/opt/OV/hpcs/hpcswatch.log";
my $hpcstracefile = "/var/opt/OV/hpcs/hpcstrace.log";
if ( $RTMACheck =~ m/Success/ || $GPCheck =~ m/Success/ )
{
my $runproc = 0;
my $term1 = "Terminating...";
my $term2 = "Termination ";
#Delete watch file once it reaches 1 MB
if(-e $hpcswatch) {
my $filesize = (-s $hpcswatch)/(1024*1024);
if( $filesize > 1 ) {
unlink $hpcswatch;
}
}
$runproc =`ps -ef | grep hpsensor | grep -v grep | awk '{print \$2}'`;
if ( $runproc eq "" )
{
my ($file, $limit) = ($hpcstracefile, 1);
open my $f, '<', $file or die;
my @lines;
$#lines = $limit;
while( <$f> ) {
shift @lines if @lines >= $limit;
push @lines, $_
}
my $check = $lines[1];
if ( ( index ( $check, $term1 ) != -1 ) || ( index ( $check, $term2 ) != -1 ) ) {
open($fh, '>>', $hpcswatch);
$datestring = localtime();
print $fh "$datestring : ####### HPCS STOPPED #######\n";
close $fh;
}
else {
open($fh, '>>', $hpcswatch);
$datestring = localtime();
print $fh "$datestring : ####### HPCS CRASH, Auto restart #######\n";
close $fh;
my $status = system($hpcsbin);
}
}
else {
open($fh, '>>', $hpcswatch);
$datestring = localtime();
chomp($runproc);
print $fh "$datestring : HPCS running with pid $runproc\n";
close $fh;
}
}
else
{
if ( !(-e $hpcswatch) )
{
open($fh, '>>', $hpcswatch);
$datestring = localtime();
print $fh "$datestring : Entity HPCS is not licensed. Install either RTMA or GP license.\n";
close $fh;
}
}