autorep -m bogus
Machine Name Max Load Current Load Factor O/S Status
___________ ________ ___________ ______ ________ ______
bogus --- --- 1.00 Sys Agent Online
Status
______
Online
Offline
Missing
Unqualified
The "Status" always "Online". I like create a script execute run 24/24 with command "break" and check if see not "Online" if see (Offline, Missing, Unqualified.....etc) then send out email. Can someone help on this code syntax....I can't make it work. Thanks
#!/bin/ksh
CHECK_MACHINE=`autorep -m bogus | awk '{print $NF}' | awk 'NR>3' | grep -v "Online"
##for file in ${CHECK_MACHINE}
##do
##if
while true
do
CHECK_MACHINE=autorep -m bogus | awk '{print $NF}' | awk 'NR>3' | grep -v "Online"
if [ ${CHECK_MACHINE} = Offline|Missing|Unqualified]
then
sleep 10; echo "Check the agent is [${CHECK_MACHINE}]" |
mailx -s "WARNING --The agent is [${CHECK_MACHINE}]" abc@test.com
break
fi
done
#!/bin/ksh
CHECK_MACHINE=autorep -m bogus | awk '{print $NF}' | awk 'NR>3' | egrep 'Offline|Missing|Unqualified'
if [ $? -ne 0 ] ; then
sleep 10; echo "Check the agent is [${CHECK_MACHINE}]" | mailx -s "WARNING --The agent is [${CHECK_MACHINE}]" abc@test.com
fi
Not sure what's cause run the code "-m: not found", but run every command line work fine.
cat abc.ksh
#!/bin/ksh
CHECK_MACHINE=autorep -m bogus | awk '{print $NF}' | awk 'NR>3' | egrep 'Offline|Missing|Unqualified'
if [ $? -ne 0 ] ; then
sleep 10; echo "Check the agent is [${CHECK_MACHINE}]" | mailx -s "WARNING --The agent is [${CHECK_MACHINE}]" abc@test.com
fi
./abc.ksh
./abc.ksh[3]: -m: not found
autorep -m bogus
Machine Name Max Load Current Load Factor O/S Status
________________________________________________________________________________ __________ ____________ _______ ___________ ______
bogus --- --- 1.00 Sys Agent Missing
autorep -m bogus | awk '{print $NF}'
Status
______
Missing
If you want your script to loop, don't exit it. And, awk will return status 0 even if no pattern found, unless told otherwise. I can't test this, as I don't have autorep available, but try
SERVERS="server1 server2 server3"
while :
do for S in $SERVERS
do CM=$(autorep -m $S |
awk 'NR<3 {next}
/Offline|Missing|Unqualified/ {print $1, $NF; exit}
{exit 1}
') &&
{ echo "check the agent is $CM"
echo "mailx -s Warning $CM abc@test.com"; } ||
sleep 10
done
done
You may want to rephrase the echoed texts, and remove the echo in front of the mailx command...
With a list separated by pipes you'd need to change the shell's internal field separator to use it in a for loop.
$ SERVERS="svr1|svr2|svr3"; for SER in $SERVERS; do echo $SER; done
svr1|svr2|svr3
$ IFS='|'; SERVERS="svr1|svr2|svr3"; for SER in $SERVERS; do echo $SER; done; unset IFS
svr1
svr2
svr3