> Bob Showalter <[EMAIL PROTECTED]> said:
> Use backticks to capture the ps -ef output and search for
> sendmail. I wouldn't send the ps|grep pipeline to the backticks,
> because on my system the ps output includes the grep command,
> which might give a "false positive".
>
> print "sendmail is up\n" if `ps -ef` =~ /sendmail/;
Some daemons like sendmail put their pid in a file, usually in /var/run. You
can then use kill to see if the process is running. Something like:
#!/usr/bin/perl -w
$SENDMAIL_PID = "/var/run/sendmail.pid";
if (! -f $SENDMAIL_PID) {
print "sendmail is not running\n";
}
else {
my $pid = `cat /var/run/sendmail.pid`;
# sendmail.pid has 2 lines
$pid =~ s/\n.*//m;
if (($ret = kill(0, $pid)) == 1) {
print "sendmail is running\n";
}
else {
print "$ret - sendmail is not running\n";
}
}
For this code to work, you must run as root, since the initiator od the kill
needs to own the killed process.
--
Smoot Carl-Mitchell
Consultant
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]