Hi all,

I have a shell programing question. I want to write a test that runs a
certain background program if it doesn't already exist. What I want to
test is this:

If the pid file doesn't exist

or

The pid file relates to a non-existing process

or

The process is not what I'm trying to run

then

run the program.


The two conditions are fairly simple to code in bash:

if [ ! -f /var/run/pid -o ! -d /proc/`cat /var/run/pid` ]

then

    /usr/bin/program

fi


The third one I'm having some difficulties with. It's fairly easy to
find out whether it's the right program or not. Something along the
lines of:

(readlink /proc/`cat /var/run/pid`/exe | grep -q progname)

will return 0 if it's the right program and 1 if it's not. In fact,
that's exactly my problem. I want the "0" and "1" to be reversed. If I did:

if [ ! -f /var/run/pid -o ! -d /proc/`cat /var/run/pid` ] || (readlink
/proc/`cat /var/run/pid`/exe | grep -q progname)

then

...


Then the program would get run if the pid file is gone, and it will get
run if the pid file is there but there is no such process, but if there
is such a process (but it's not the right one) it will not get run, and
if there is such a process and it is the right one, the process will be
run again!


Any ideas on how to correctly code this piece of code would be greatly
appreciated.

          Shachar

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to