Ext script not looping
list Ricardo L.
I have this script work is failing on all hosts except the first one.
I have narrowed it down to the ssh statement. For some reason the ssh statement causes the script to exit after the first host.
Any ideas why the ssh statement would cause the ext script to exit after the first host ?
#!/bin/sh
export PATH=$PATH:/sbin:/bin:/usr/bin:/usr/local/bin:/usr/sbin:/usr/local/bin
HOSTTAG=zfsmon # What we put in hosts.cfg to trigger this test
COLUMN=zfs # Name of the column, often same as tag in hosts.cfg
$XYMONHOME/bin/xymongrep $HOSTTAG | while read L
do
set $L # To get one line of output from xymongrep
HOSTIP="$1"
MACHINEDOTS="$2"
MACHINE=`echo $2 | $SED -e's/\./,/g'`
COLOR=green
MSG="&green $MACHINEDOTS : POOL OK "
#... do the test, perhaps modify COLOR and MSG
typeset ZFSSTAT=
ZFSHEALTH=`/usr/local/bin/ssh $MACHINE "/sbin/zpool get health rpool" | grep ONLINE | wc -l`
if [ $ZFSHEALTH -ne 1 ]
then
COLOR=red
MSG="&red $MACHINEDOTS : POOL ISSUE"
fi
ZFSSTAT=`ssh -q $MACHINE /sbin/zpool status rpool`
$XYMON $XYMSRV "status $MACHINE.$COLUMN $COLOR `date`
${MSG}
$ZFSSTAT
"
Done
list Steve Coile
Ensure ssh isn't reading from standard input by using the -n option: ZFSHEALTH=`/usr/local/bin/ssh -n $MACHINE "/sbin/zpool get health rpool" | grep ONLINE | wc -l` ZFSSTAT=`ssh -n -q $MACHINE /sbin/zpool status rpool` -- *Steve Coile*Senior Network and Systems Engineer, McClatchy Interactive <http://www.mcclatchyinteractive.com/>; Office: XXX-XXX-XXXX | Mobile: XXX-XXX-XXXX | Fax: XXX-XXX-XXXX
▸
On Wed, Sep 24, 2014 at 10:00 AM, Ricardo L. <user-7954c4ed4af4@xymon.invalid> wrote:
I have this script work is failing on all hosts except the first one.
I have narrowed it down to the ssh statement. For some reason the ssh
statement causes the script to exit after the first host.
Any ideas why the ssh statement would cause the ext script to exit after
the first host ?
#!/bin/sh
export
PATH=$PATH:/sbin:/bin:/usr/bin:/usr/local/bin:/usr/sbin:/usr/local/bin
HOSTTAG=zfsmon # What we put in hosts.cfg to trigger this test
COLUMN=zfs # Name of the column, often same as tag in
hosts.cfg
$XYMONHOME/bin/xymongrep $HOSTTAG | while read L
do
set $L # To get one line of output from xymongrep
HOSTIP="$1"
MACHINEDOTS="$2"
MACHINE=`echo $2 | $SED -e's/\./,/g'`
COLOR=green
MSG="&green $MACHINEDOTS : POOL OK "
#... do the test, perhaps modify COLOR and MSG
typeset ZFSSTAT=
ZFSHEALTH=`/usr/local/bin/ssh $MACHINE "/sbin/zpool get health
rpool" | grep ONLINE | wc -l`
if [ $ZFSHEALTH -ne 1 ]
then
COLOR=red
MSG="&red $MACHINEDOTS : POOL ISSUE"
fi
ZFSSTAT=`ssh -q $MACHINE /sbin/zpool status rpool`
$XYMON $XYMSRV "status $MACHINE.$COLUMN $COLOR `date`
${MSG}
$ZFSSTAT
"
Done
list Paul Root
I have a couple questions. Why are you ssh’ing twice to the machine for the same information.
And why are you using 2 different ssh clients?
And which ssh is exiting the script?
What version of Solaris are you using? What are the versions of the ssh clients? What version of xymon are you using?
I’d do:
ZFSSTAT=`ssh -q $MACHINE /sbin/zpool status rpool`
ZFSHEALTH=`echo $ZFSSTAT| grep ONLINE | wc -l`
▸
if [ $ZFSHEALTH -ne 1 ]
then
COLOR=red
MSG="&red $MACHINEDOTS : POOL ISSUE"
fi
$XYMON $XYMSRV "status $MACHINE.$COLUMN $COLOR `date`
${MSG}
$ZFSSTAT
"
From: Xymon [mailto:xymon-bounces at xymon.com] On Behalf Of Ricardo L.
Sent: Wednesday, September 24, 2014 9:01 AM
To: xymon at xymon.com
Subject: [Xymon] Ext script not looping
I have this script work is failing on all hosts except the first one.
I have narrowed it down to the ssh statement. For some reason the ssh statement causes the script to exit after the first host.
Any ideas why the ssh statement would cause the ext script to exit after the first host ?
#!/bin/sh
export PATH=$PATH:/sbin:/bin:/usr/bin:/usr/local/bin:/usr/sbin:/usr/local/bin
HOSTTAG=zfsmon # What we put in hosts.cfg to trigger this test
COLUMN=zfs # Name of the column, often same as tag in hosts.cfg
$XYMONHOME/bin/xymongrep $HOSTTAG | while read L
do
set $L # To get one line of output from xymongrep
HOSTIP="$1"
MACHINEDOTS="$2"
MACHINE=`echo $2 | $SED -e's/\./,/g'`
COLOR=green
MSG="&green $MACHINEDOTS : POOL OK "
#... do the test, perhaps modify COLOR and MSG
typeset ZFSSTAT=
ZFSHEALTH=`/usr/local/bin/ssh $MACHINE "/sbin/zpool get health rpool" | grep ONLINE | wc -l`
if [ $ZFSHEALTH -ne 1 ]
then
COLOR=red
MSG="&red $MACHINEDOTS : POOL ISSUE"
fi
ZFSSTAT=`ssh -q $MACHINE /sbin/zpool status rpool`
$XYMON $XYMSRV "status $MACHINE.$COLUMN $COLOR `date`
${MSG}
$ZFSSTAT
"
Done
list Ricardo L.
Hi Paul You are right that is the proper way to do it. I left it as is because I was testing / debugging. Steve was correct the -n fixed the issue. I will now go back and only do one ssh. Thanks On Wed, Sep 24, 2014 at 9:17 AM, Root, Paul T <user-76fdb6883669@xymon.invalid>
▸
wrote:
I have a couple questions. Why are you ssh’ing twice to the machine for the same information.
And why are you using 2 different ssh clients?
And which ssh is exiting the script?
What version of Solaris are you using? What are the versions of the ssh clients? What version of xymon are you using?
I’d do:
ZFSSTAT=`ssh -q $MACHINE /sbin/zpool status rpool`
ZFSHEALTH=`echo $ZFSSTAT| grep ONLINE | wc -l`
if [ $ZFSHEALTH -ne 1 ]
then
COLOR=red
MSG="&red $MACHINEDOTS : POOL ISSUE"
fi
$XYMON $XYMSRV "status $MACHINE.$COLUMN $COLOR `date`
${MSG}
$ZFSSTAT
"
From: Xymon [mailto:xymon-bounces at xymon.com] On Behalf Of Ricardo L.
Sent: Wednesday, September 24, 2014 9:01 AM
To: xymon at xymon.com
Subject: [Xymon] Ext script not looping
I have this script work is failing on all hosts except the first one.
I have narrowed it down to the ssh statement. For some reason the ssh statement causes the script to exit after the first host.
Any ideas why the ssh statement would cause the ext script to exit after the first host ?
#!/bin/sh
export PATH=$PATH:/sbin:/bin:/usr/bin:/usr/local/bin:/usr/sbin:/usr/local/bin
HOSTTAG=zfsmon # What we put in hosts.cfg to trigger this test
COLUMN=zfs # Name of the column, often same as tag in hosts.cfg
$XYMONHOME/bin/xymongrep $HOSTTAG | while read L
do
set $L # To get one line of output from xymongrep
HOSTIP="$1"
MACHINEDOTS="$2"
MACHINE=`echo $2 | $SED -e's/\./,/g'`
COLOR=green
MSG="&green $MACHINEDOTS : POOL OK "
#... do the test, perhaps modify COLOR and MSG
typeset ZFSSTAT=
ZFSHEALTH=`/usr/local/bin/ssh $MACHINE "/sbin/zpool get health rpool" | grep ONLINE | wc -l`
if [ $ZFSHEALTH -ne 1 ]
then
COLOR=red
MSG="&red $MACHINEDOTS : POOL ISSUE"
fi
ZFSSTAT=`ssh -q $MACHINE /sbin/zpool status rpool`
$XYMON $XYMSRV "status $MACHINE.$COLUMN $COLOR `date`
${MSG}
$ZFSSTAT
"
Done