Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl Job that kills actice jobs in Linux vs Unix

Status
Not open for further replies.

djbow

Programmer
Nov 29, 2006
12
US
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;
}
 
Can you post what the logfile says?

If at first you don't succeed, don't try skydiving.
 
>> and the script is not working

whats not working? Is the script dieing, aborting with errors, running but not producing output, or what?

- Kevin, perl coder unexceptional!
 
Quick question, does the user running the kill script have the necessary credentials to kill processes of other users or is hrdw_search.pl ran by the same user?

Secondly, you may want to flush out an else statement for the if ($? == 0 ) block to see if the return value from the kill command may provide additional information.

Ethan
 
To answer netman4u, nothing is showing up on the log file

To Kevin, it appears that the script is working, no errors are being produced however the job still lives.

To babock - hrdw_search.pl is ran by the same user as the kill program.

 
Code:
if ($? == 0 )
{
    &log_msg(" Search Process successfully terminated by $jobname.");
} else {
    &log_msg(" Jobs may not be terminated. Kill returned $?.");
}

Nothing is logged because there is no else clause to handle the return value from the "kill" command when the value is not 0.
 
run this shell stuff from the command ine and see if it produces any output on it's own:

ps -ef | grep hrdw_search.pl | grep -v grep

- Kevin, perl coder unexceptional!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top