HEX
Server: Apache/2.4.34 (Red Hat) OpenSSL/1.0.2k-fips
System: Linux WORDPRESS 3.10.0-1160.118.1.el7.x86_64 #1 SMP Thu Apr 4 03:33:23 EDT 2024 x86_64
User: digital (1020)
PHP: 7.2.24
Disabled: NONE
Upload Files
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;
	}
}