Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ping with a sun script

Status
Not open for further replies.

visvid

Technical User
Jun 3, 2002
131
GB
Hi can anyone help, looking to see if anyone knows how to give me an ip address back from a ping on sun, as it just says alive:

I am wanting to test printers on the system
#!/bin/ksh
###### Script to Test remote printers are working ###########################
for n in `pg /etc/printers.conf | grep :bsdaddr | awk -F= '{print $2}' | awk -F, '{print $1}'`

do
A=`ping -c 1 $n 2>/dev/null`
if [ -z "$A" ]; then
B="NOTFOUND"
else
B=`echo "$A" | grep packet | awk '{print $(NF-2)}'`
fi

if [ $B = "100%" ]; then
echo $n FAILED
elif [ $B = "0%" ]; then
echo $n OK
else
echo $n NOT FOUND
fi

done
##### NF=Number of Fields

this -c 1 works great with AIX , but cant find syntax to work on Sun. Any ideas
 
I guess $n is a ip, right?

try it:
if ping $n
then
B=`echo "$A" | grep packet | awk '{print $(NF-2)}'`
else
B="NOTFOUND"
fi
.
.
.


tikual
 
no $n is the names of the printer , hence we get "is alive " when we run the script rather than IP address
 
ok, ping name or ip just same.

#-s : if no -s, it just gives you alive or not, -s is for continously.
#64 : size of packets
#10 : time of court, that means send packets ten times
if ping -s $n 64 10
then
B=`echo "$A" | grep packet | awk '{print $(NF-2)}'`
else
B="NOTFOUND"
fi
.
.
.

tikual
 
Just an idea, how about trying a different method?
the command "traceroute hostname" can be verbose but will supply an IP address. Or "grep hostname /etc/hosts"
 
A=`ping -s $n 56 1 2> /dev/null`


work great , cheers for help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top