Actually in plain vanilla sh the string comparison operator *is* "=", not
"==" (although bash will accept either).

One of those gotchas designed to drive Perl and C programmers nuts.

Scott Prater
Dpto. Sistemas
[EMAIL PROTECTED]

SERVICOM 2000
Av. Primado Reig, 189 entlo.
46020 Valencia - Spain
Tel. (+34) 96 332 12 00
Fax. (+34) 96 332 12 01
www.servicom2000.com




-----Mensaje original-----
De: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]En
nombre de Ralph.Bugg
Enviado el: martes, 21 de mayo de 2002 14:10
Para: 'Peter Mueller'; '[EMAIL PROTECTED]'
Asunto: RE: monitor a pid?


Peter,

        The problem is with the code

if [ $9 = "-u" ]; then
        $HEARTBEAT restart
else
        $HEARTBEAT stop
fi

What you really want is
if [ $9 == "-u"]; then

the single '=' is for assignment, not for testing equiviance...
What's happening is that the heartbeat isn't running and it can't seem to
get it started again
Thus it keeps tripping the alarm and trying to restart your heartbeat
process (which is can't and the fact that it's not running causes an alarm
to be thrown ad nausium...

Although it's better if you have it as
if [ "X$9" == "X-u"]; then

So that if $9 doesn't exist you won't get an error

Hope this helps,
--
Ed Bugg <[EMAIL PROTECTED]>
Network Operations
BlueCross and BlueShield of MO

-----Original Message-----
From: Peter Mueller [mailto:[EMAIL PROTECTED]]
Sent: Monday, May 20, 2002 3:07 PM
To: '[EMAIL PROTECTED]'
Subject: FW: monitor a pid?


If this works - thanks Jim!

-----Original Message-----
From: Peter Mueller
Sent: Wednesday, May 15, 2002 11:59 AM
To: '[EMAIL PROTECTED]'
Subject: monitor a pid?


hi,

newbie question.  how does everyone here recommend monitoring a pid?  I was
playing around with this a _while_ back and I could never get it to work..
my PID heartbeat just seems to restart endlessly!.  help help plz :)

Peter

mon version = mon-0.99.2

<mon errfile log>
[root@fe4028 mon]# cat errfile
/usr/src/mon/alert.d/heartbeat.alert: [: =: unary operator expected
Stopping High-Availability services: [  OK  ]
/usr/src/mon/alert.d/heartbeat.alert: [: =: unary operator expected
Stopping High-Availability services: [  OK  ]
/usr/src/mon/alert.d/heartbeat.alert: [: =: unary operator expected
Stopping High-Availability services: [  OK  ]
/usr/src/mon/alert.d/heartbeat.alert: [: =: unary operator expected
Stopping High-Availability services: [  OK  ]
/usr/src/mon/alert.d/heartbeat.alert: [: =: unary operator expected

<part of mon.cf>
watch heartbeat
        service heartbeat
                interval 15s
                monitor pid.monitor heartbeat
                depend gateway:fping
                dep_behavior m
                period NORMAL: wd {Sun-Sat}
                        alert restart.alert heartbeat
<pid.monitor>
#!/bin/sh
# Script for mon to check wether a process is running or not.
# Invoke with
# monitor pid.monitor process

/sbin/pidof -s $1 > /dev/null 2>&1

if [ $? -eq "0" ]; then
        echo "$1 running"
        exit 0
else
        echo "$1 not running"
        exit 1
fi

<restart.alert>
#!/bin/bash
# Script to start/stop heartbeat daemon

HEARTBEAT="/etc/rc.d/init.d/heartbeat"

if [ $9 = "-u" ]; then
        $HEARTBEAT restart
else
        $HEARTBEAT stop
fi

Reply via email to