1847084 Members
5991 Online
110262 Solutions
New Discussion

HP-UX Script

 
SOLVED
Go to solution
NOR AZLY MOHD NOR
Occasional Contributor

HP-UX Script

Hi,

I just wrote some script in HP-UX regarding the ECHO ping.

when I execute a command
IP="202.202.202.202 (example)
and then
/usr/sbin/ping $IP -n 1 |wc -c

a return value is 226.

so when I change the IP to a fake IP let say IP=202.202.202.203 and I execute a command
/usr/sbin/ping $IP -n 1 |wc -c

a return value is 135.

After tht I execute a same command with real IP so I get return value is 230.

So my question i how can I put a two condition where are if return values is 226 OR 230 so a retval=1. My example script

IP="202.202.202.202"

CONTACT=$(/usr/sbin/ping $IP -n 1 | wc -c)
if [ "$CONTACT" -eq 226 ]
then
retval=0
else
retval=1
fi
echo "Destination Status" $retval
return retval
6 REPLIES 6
Frederic Sevestre
Honored Contributor
Solution

Re: HP-UX Script

Hello,

Try :

CONTACT=$(/usr/sbin/ping $IP -n 1 | wc -c)
if [ "$CONTACT" -eq 226 -o "$CONTACT" -eq 230 ]
then
retval=0
else
retval=1
fi
echo "Destination Status" $retval
return retval

Then you will have retval = 0 for CONTACT = 226 OR 230.

Regards,
Fr??d??ric

Crime doesn't pay...does that mean that my job is a crime ?
Niraj Kumar Verma
Trusted Contributor

Re: HP-UX Script

IP="202.202.202.202"

CONTACT=$(/usr/sbin/ping $IP -n 1 | wc -c)
if [ "$CONTACT" -eq 226 -o "$CONTACT" -eq 230 ]
then
retval=0
else
retval=1
fi
echo "Destination Status" $retval

Niraj.Verma@philips.com
john korterman
Honored Contributor

Re: HP-UX Script

Hi,
for a limited number of return values, you could make use of a case-structure, e.g.:

case $CONTACT in
226) retval=0;;
230) retval=0;;
*) retval=1;;
esac

regards,
John K.
it would be nice if you always got a second chance
Niraj Kumar Verma
Trusted Contributor

Re: HP-UX Script

Hi,

If you are looking for a script to monitor the network
check this

#!/bin/sh
IP="202.202.202.202"
CONTACT=$(/usr/sbin/ping $IP -n 1 |tail -2 |grep "%" |tail -1 |awk -F"," '{print $3}'|awk -F"%" '{print $1}')

if [ "$CONTACT" -lt 100 ]
then
echo "LINK UP"
else
echo "LINK Down"
fi

-Niraj
Niraj.Verma@philips.com
NOR AZLY MOHD NOR
Occasional Contributor

Re: HP-UX Script

Hi,

Thanks everyone.


My problem resolves.



AZLY
Dietmar Konermann
Honored Contributor

Re: HP-UX Script

Hmm, besides this discussion about checking for multiple cases... looks like you are checking for the byte count of the messages returned by ping? Seems to be a liitle bit risky INHO...

What about...

ping $IP -n 1 | grep -q "bytes from"
retval=$?
echo "Destination Status" $retval
return retval

Best regards...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)