Hi!
$? would give the status of the last command so you need to test them independently.
tmsh show ltm pool Mypool1_Stg_pool field-fmt | grep -o offline > /dev/null
tmsh show ltm pool Mypool2_Stg_pool field-fmt | grep -o offline > /dev/null
status=$?
This would only return the exit code of:
tmsh show ltm pool Mypool2_Stg_pool field-fmt | grep -o offline > /dev/null
Example:
This command works:
[root@PatrikLab:Active] config ls bigip.conf > /dev/null
[root@PatrikLab:Active] config echo $?
0
This command does not work:
[root@PatrikLab:Active] config ls nonexistingfile > /dev/null
ls: nonexistingfile: No such file or directory
[root@PatrikLab:Active] config echo $?
2
Run them together:
[root@PatrikLab:Active] config ls nonexistingfile > /dev/null
ls: nonexistingfile: No such file or directory
[root@PatrikLab:Active] config ls bigip.conf > /dev/null
[root@PatrikLab:Active] config echo $?
0
So maybe you'd want to do something like this?
!/bin/sh
pidfile="/var/run/pinger.$1..$2.pid"
if [ -f $pidfile ]
then
kill -9 `cat $pidfile` > /dev/null 2>&1
fi
echo "$$" > $pidfile
node_ip=`echo $1 | sed 's/::ffff://'`
status="UP"
tmsh show ltm pool Mypool1_Stg_pool field-fmt | grep -o offline > /dev/null
if [ $? ]; then
status="DOWN";
fi
tmsh show ltm pool Mypool2_Stg_pool field-fmt | grep -o offline > /dev/null
if [ $? ]; then
$status="DOWN"
fi
echo $status
/Patrik