ALLPIDS is a list of PIDs of all processes with 'fetchmail' in the output of 'ps aux' (first is fetchmail if running, second is grep). FIRSTPID is the first in that list.
It wasn't *that* bad.
Yeah, I noticed after my second read through.. Altho I would stay with the 'KIVS' (Keep It Very Safe) principle on this one.. ie:
Code:
#!/bin/sh
PID_R=`ps aux| grep -v grep| grep fetchmail| grep $USER| awk '{print $2}'`
if [ -f ~/.fetchmail.pid ]; then
*PID_F=`cat ~/.fetchmail.pid`
*if [ x"$PID_R" = x ]; then
* echo "Fetchmail isn't running, and was last killed by SIGKILL"
*else *
* *if [ "$PID_F" = "$PID_R" ]; then
* * * *echo "Fetchmail is running as: $PID_R"
* *else
* * * echo "Something wierd happened, fetchmail is running, but not as the PID listed in its lockfile"
* *fi
*fi
else
*if [ x"$PID_R" = x ]; then
* echo "Fetchmail isn't running"
*else
* *echo "Something wierd happened, fetchmail is running, but with no lockfile"
*fi
fi
(none of the code above has been tested, but it should work out of the box)
But true enough, given the fact that using a '| grep' on a 'ps aux' output seems to eliminate other users listings, your's is doing the job just fine.
Bookmarks