#!/usr/bin/perl
# $Date: 2004/03/22 01:13:00 $ $Revision: 1.2 $
use strict;
my @lines = split /\n/, `ps -axw|grep $ARGV[0]`;
my @dummy = split /\//, $0;
my $SCRIPT_SHORT = $dummy[$#dummy];
my $RUNNING = 0;
my $PID = 0;
foreach (@lines) {
next if $_ =~ /grep $ARGV[0]/ or $_ =~ /$SCRIPT_SHORT $ARGV[0]/;
$RUNNING++;
$PID = $_; $PID += 0;
print $PID unless $ARGV[1] eq 'status';
last;
}
if ($ARGV[1] eq 'status') {
print $RUNNING ? "Running [$PID]" : 'Stopped';
}
Save this script as getpid under /usr/local/bin/.
Usage
getpid {process_name} [status]
getpid smsbox
getpid smsbox status