1833457 Members
3167 Online
110052 Solutions
New Discussion

Re: ping problem

 
SOLVED
Go to solution
Thi Vu
Frequent Advisor

ping problem

Hello,

I have a little script that run every 30 min to see if the system is up or down. So I used this command in my script :

variable=ping hostname(s) -n 2 |grep 0% |awk '{print $7}'
and if the $variable != 0 then it'll send a message to said that system fail. This had been running fine for the last couple of months but this month I keep getting emailx saying that system1 or system2 ... systemn fail and when I went to investigate (manually pinging the system or log into the system - it's OK). I had this running on 5 systems and randomly each one send false report. It even happens when I'm currently working in system. Any help is appreciated.

TIA
Thi
12 REPLIES 12
ramesh_6
Frequent Advisor

Re: ping problem

Hi

ping hostname -n 2 | grep 0% | awk '{print $7}' is producing the output 0%

i.e your variable is set to a value = 0%

If your $variable != 0 ( here it is 0% ) it will e-mail you a failure message. Since 0 and o% are not equal you are getting a failure message.

To avoid this the in the comaprison line use

$variable != 0% then send an e-mail informing you of a failure.

Regds
Ramesh
Thi Vu
Frequent Advisor

Re: ping problem

Opps, typo it was $variable != 0%. Sorry

Thi
S.K. Chan
Honored Contributor

Re: ping problem

You might want to increase the ping count to more than what you have, say "-n 5", so that it gives some time for slow responding system to respond to your ping request.
Thi Vu
Frequent Advisor

Re: ping problem

I increased it to 7 but still got the same problem.

Thi
linuxfan
Honored Contributor
Solution

Re: ping problem

Hi,

Do you have any network issues at all? because from what you are saying, if $variable != 0% , the script will send an email, what if you are losing some network packets?

One way to check would be to send the $variable in the email.

-HTH
Ramesh
They think they know but don't. At least I know I don't know - Socrates
S.K. Chan
Honored Contributor

Re: ping problem

Can you attach the script that you used ? Also are there any changes to the network infrastructure prior to the failure of yr script ?
someone_4
Honored Contributor

Re: ping problem

Hello Thi,
I use and it works great. You can makethe then and else statements do do whatever you want. And iphosts.file can is a file with the hostnames or ip address in one colum.

#!/bin/sh
LANG=C
HOSTNAME_FILE=iphosts.file
for host in $(cat $HOSTNAME_FILE)
do
ping $host -n 1 | grep -q '1 packets received'
if [ $? = 0 ]
then
echo "$host: OK"
else
echo "$host: FAIL"
fi
done


Richard
MANOJ SRIVASTAVA
Honored Contributor

Re: ping problem

Hi Thi

I think like this , if your script was working fine there should be nothing wrong with it except that there are changes in the ports where the servers are connected or there are really errors.You may want to try this

export A=`ping $HOSTNAME -n 2 | grep 0% | awk '{print $7}'|cut -c 1 `

though I know this is not right .


Manoj Srivastava
Mark Fenton
Esteemed Contributor

Re: ping problem

Agree with Ramesh -- sending $variable in the email would help to clarify whether the false reports were due to losing a few packets.
When you run the program in the foreground (sh -vx xyzutil) -- what is the output?

I jotted down a test script and ran it like so
hostname=$1

variable=`ping $hostname -n 10 |grep 0% |awk '{print $7}'`
if [ $variable != 0% ]
then
echo "failure -- $hostname lost $variable of the packets"
else
echo "success -- $hostname appears to be up"
fi

and it functions as I would expect.

hth
Mark
Ron Kinner
Honored Contributor

Re: ping problem

ICMP is a low priority task for many devices so if they get a bit busy you might lose a ping or two. Very common with switches. I see this quite often.

You may also have some network congestion issues, noise on WAN links, duplex mismatches, queue drops in routers etc which would kill a ping but which get shrugged off by telnet since it uses TCP which simply resends a lost packet.

You might want to check netstat -s and see if you see any problems. Do this several times and look for increases in retransmissions and errors.

Also
lanadmin
lan
display


will show any Ethernet problems (especially not the second page).

Do this at both ends of the circuit.

Ron

F.J.Llorente Wayfarer
Frequent Advisor

Re: ping problem

Well, if it is just to check if the node is active, a good solution could be to another ping if first ping fails. I'd do, say, five pings before marking a node as faulty.

Or maybe you can mark that node as 'posibly faulty' when the first ping fails, ping it again a minute or two before.

Hope it'll work...

Regards.
A patch a day keeps problems away
Thi Vu
Frequent Advisor

Re: ping problem

Thank you everyone for the response. I did as per Ramesh's suggestion and found that sometime the ping status return a non zero value.

Thi