CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Returning output only if command kills job



Nov 28, 2015, 7:14 PM

Post #1 of 2 (1464 views)
Returning output only if command kills job Can't Post

I have a command killx that kills certain jobs that run. I was trying to figure out how to get the output only if the command actually kills a job. Right now it runs whether a job is killed or not. So I get 0 cancelled or 1 (or more jobs) cancelled. I just want the command to print output if it does cancel a job. Is there a way to do this?
So basically the script works (array4 is from a previous portion of the script). I want to focus only on trimming the print function from printing every action of the killx to printing only when a job is killed.

if (@unique) { 
my $output;
foreach my $job (@array4) {

$output = `/bin/killx -cancel $job`;
print "$output\n";
else {
print "No duplicates to kill";


Nov 28, 2015, 8:36 PM

Post #2 of 2 (1461 views)
Re: [regex2012] Returning output only if command kills job [In reply to] Can't Post

Analyze $output with a regular expression.

Assuming that killx NEVER returns any other output that you might want and that you have correctly described the output message, you could use:

        $output = `/bin/killx -cancel $job`; 
$output =~ /(\d\d?)\s+cancelled/;
print "$output\n" if defined($1) and $1 > 0;

Good Luck,


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives