First of all let me state that I know nothing about Perl. I have inherited this project and there is a Perl script that kills the job if it is running that works on our old Unix box. We are now moving to a new Linux OS on IBM Blade servers and the script is not working. The program runs but the processes are not killed. Any suggestion at all? Sorry for the vague post but I am completely lost.
Code:
#!/usr/bin/perl
#-------------------------------------------------------------------------------
# Setup
#-------------------------------------------------------------------------------
$jobname = "hrdw_searchstop";
$hrftp = $ENV{"HOM"} || die "\n$jobname ERROR - CANNOT GET HRFTP\n";
$hrbin = $ENV{"BIN"} || die "\n$jobname ERROR - CANNOT GET HRBIN\n";
$hrsql = $ENV{"SQL"} || die "\n$jobname ERROR - CANNOT GET HRSQL\n";
$hrdat = $ENV{"DAT"} || die "\n$jobname ERROR - CANNOT GET HRDAT\n";
$hrctl = $ENV{"CTL"} || die "\n$jobname ERROR - CANNOT GET HRCTL\n";
$hrlog = $ENV{"LOG"} || die "\n$jobname ERROR - CANNOT GET HRLOG\n";
$hrerr = $ENV{"ERR"} || die "\n$jobname ERROR - CANNOT GET HRERR\n";
# This process writes to the main hrdw_search.log logfile
$logfile = "$hrlog/hrdw_search.log";
open (LOGFILE, ">>$logfile") || die "\nCANNOT OPEN FILE $logfile\n";
select(STDERR); $| = 1; # make unbuffered
select(STDOUT); $| = 1; # make unbuffered, default print to STDOUT
#-------------------------------------------------------------------------------
# Get PID of hrdw_search process & kill if running
#-------------------------------------------------------------------------------
($user, $pid) = split (' ', `ps -ef | grep hrdw_search.pl | grep -v grep`);
if (defined($pid))
{
`kill -9 $pid`;
if ($? == 0 )
{
&log_msg(" Search Process successfully terminated by $jobname.");
}
}
else
{
print "\n\n Search Process WAS NOT RUNNING! \n\n";
}
&end;
#-------------------------------------------------------------------------------
# Log Msg
#-------------------------------------------------------------------------------
sub log_msg
{
local ($msg) = @_;
@stime = localtime(time);
$stime[4]++;
printf LOGFILE "$jobname %02d/%02d/%02d %02d:%02d:%02d $msg\n", $stime[4], $stime[3], $stime[5], $stime[2], $stime[1], $stime[0];
}
#-------------------------------------------------------------------------------
# End
#-------------------------------------------------------------------------------
sub end
{
close (LOGFILE);
exit 0;
}