#!/usr/bin/env perl
use warnings;
use strict;
my $com1;
# replace call to ps with your ps output for this example:
$com1 = <<EOF;
weblogic start
weblogic /export/home/weblogic/bai/bpps.sh
EOF
print "1st\n";
check_for_bpps($com1);
# now assume that ps show that bpps is NOT running:
$com1 = 'foo bar';
print "2nd\n";
check_for_bpps($com1);
exit;
sub check_for_bpps {
my $com1 = shift;
if ($com1 =~ /weblogic/) {
print "bpps is running.\n";
}
else {
print "running com2.\n";
#$com2 = `sh -c /export/home/weblogic/bai/bpps.sh start 2 > /d
+ev/null 2>&1`;
}
}
When I run this, I get the following output:
1st
bpps is running.
2nd
running com2.
The key here is that I'm using a regular expression to search for the 'weblogic' string in your ps output. |