I believe the "unary operator expected" error is occurring in the line:

if [ $9 = "-u" ]; then

Whenever I do shell scripting, I always use the trick explained in _Unix
Power Tools_:  instead of
    if [ $9 = "-u" ]
do
    if [ "X$9" = "X-u" ]

That way, the test will never fail, even if $9 doesn't exist.  Shell scripts
tend to be agonizingly literal:  if the variable doesn't exist, the shell
will replace "$9" with nothing;  and hence, the error in the test condition.

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 Peter Mueller
Enviado el: lunes, 20 de mayo de 2002 22:07
Para: '[EMAIL PROTECTED]'
Asunto: 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