PING broken check


 
Thread Tools Search this Thread
Operating Systems Solaris PING broken check
# 8  
Old 06-21-2011
sleep 5 -- waiting for 5 seconds, after that we are pinging the host

Code:
#!/bin/sh
for i in `cat /tmp/PingStatus.txt`
do
sleep 5; ping $i | grep -w "alive" && echo "$i is OK" || opcmsg object=PING a=OS msg_grp=OpC severity=critical msg_text="PING BROKEN on $i"
done

This User Gave Thanks to itkamaraj For This Post:
# 9  
Old 06-21-2011
Quote:
Originally Posted by itkamaraj
sleep 5 -- waiting for 5 seconds, after that we are pinging the host

Code:
#!/bin/sh
for i in `cat /tmp/PingStatus.txt`
do
sleep 5; ping $i | grep -w "alive" && echo "$i is OK" || opcmsg object=PING a=OS msg_grp=OpC severity=critical msg_text="PING BROKEN on $i"
done

That's a useless use of cat and useless use of backticks. Whenever you have for x in `cat file` you can do it better as

Code:
#!/bin/sh
while read i
do
sleep 5; ping $i | grep -w "alive" && echo "$i is OK" || opcmsg object=PING a=OS msg_grp=OpC severity=critical msg_text="PING BROKEN on $i"
done < /tmp/PingStatus.txt

That way you're not trying to cram entire files into shell variables at once and potentially truncating them.

Last edited by Corona688; 06-21-2011 at 12:25 PM..
This User Gave Thanks to Corona688 For This Post:
# 10  
Old 06-21-2011
Need to discuss a general query:

root@ggnems21 # ping -s ggnems23
PING ggnems23: 56 data bytes
64 bytes from ggnems23.aircel.co.in (172.18.124.38): icmp_seq=0. time=17.6 ms
64 bytes from ggnems23.aircel.co.in (172.18.124.38): icmp_seq=1. time=38.3 ms
64 bytes from ggnems23.aircel.co.in (172.18.124.38): icmp_seq=2. time=122. ms
64 bytes from ggnems23.aircel.co.in (172.18.124.38): icmp_seq=3. time=235. ms
64 bytes from ggnems23.aircel.co.in (172.18.124.38): icmp_seq=4. time=24.8 ms
^C
----ggnems23 PING Statistics----
5 packets transmitted, 5 packets received, 0% packet loss
round-trip (ms) min/avg/max/stddev = 17.6/87.5/235./92.


when is Ping Broken is valid ? i.e at what packet percentage i should comment it as PING BROKEN?

---------- Post updated at 01:10 AM ---------- Previous update was at 01:07 AM ----------

at what percentage packet loss?
If so then i would require this packet loss percetage to be included within my script
# 11  
Old 06-21-2011
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
# 12  
Old 06-21-2011
Quote:
Originally Posted by Corona688
That's a useless use of cat and useless use of backticks. Whenever you have for x in `cat file` you can do it better as

Code:
#!/bin/sh
while read i
do
sleep 5; ping $i | grep -w "alive" && echo "$i is OK" || opcmsg object=PING a=OS msg_grp=OpC severity=critical msg_text="PING BROKEN on $i"
done < cat /tmp/PingStatus.txt

That way you're not trying to cram entire files into shell variables at once and potentially truncating them.
@corona

thanks for your tips.

any way, in the while loop, we dont want to put cat

cat /tmp/PingStatus.txt

we can use /tmp/PingStatus.txt itself

correct me, if i am wrong
# 13  
Old 06-21-2011
Quote:
Originally Posted by itkamaraj
@corona

thanks for your tips.

any way, in the while loop, we dont want to put cat

cat /tmp/PingStatus.txt

we can use /tmp/PingStatus.txt itself

correct me, if i am wrong
You are correct. the 'cat' was left in by accident, sorry.
# 14  
Old 06-21-2011
Quote:
Originally Posted by mjoshi87
Need to discuss a general query:

root@ggnems21 # ping -s ggnems23
PING ggnems23: 56 data bytes
64 bytes from ggnems23.aircel.co.in (172.18.124.38): icmp_seq=0. time=17.6 ms
64 bytes from ggnems23.aircel.co.in (172.18.124.38): icmp_seq=1. time=38.3 ms
64 bytes from ggnems23.aircel.co.in (172.18.124.38): icmp_seq=2. time=122. ms
64 bytes from ggnems23.aircel.co.in (172.18.124.38): icmp_seq=3. time=235. ms
64 bytes from ggnems23.aircel.co.in (172.18.124.38): icmp_seq=4. time=24.8 ms
^C
----ggnems23 PING Statistics----
5 packets transmitted, 5 packets received, 0% packet loss
round-trip (ms) min/avg/max/stddev = 17.6/87.5/235./92.


when is Ping Broken is valid ? i.e at what packet percentage i should comment it as PING BROKEN?

---------- Post updated at 01:10 AM ---------- Previous update was at 01:07 AM ----------

at what percentage packet loss?
If so then i would require this packet loss percetage to be included within my script


i try some script for your needs Smilie
Code:
# cat pinglist
localhost
localhost2
192.168.80.130

you can use this format "./testping.sh counts(packet try) hostlistfile"
and i defined some values in script like ; pingloss of percent(threshold value)=%50 ; send packet try waits=2..
but you change all settings if you think what about its..
for example
Code:
# ./testping.sh 1 pinglist
"localhost" is alive with "%0 of %100 loss rate" at 1 packet tries in 2 seconds intervals
 
ping: unknown host localhost2
ping failed while sending 'echo_request(s)' to "localhost2"
check!! host access (/network or firewall or route(ing) settings/) or
check!! resolution (/hosts/dns/nsswitch)!!
or
check!! be sure host is power up or
check!! is ping enabled in o.s or switch(s) or router(s)
 
ping failed while sending 'echo_request(s)' to "192.168.80.130"
check!! host access (/network or firewall or route(ing) settings/) or
check!! resolution (/hosts/dns/nsswitch)!!
or
check!! be sure host is power up or
check!! is ping enabled in o.s or switch(s) or router(s)

Code:
# cat testping.sh
## justdoit ## ping test on SUN OS ##
#!/usr/bin/bash
if [ $# != 2 ] ; then echo "usage $0 'packetcount' hostlistfile" ; exit 0 ; fi
sleep=2 ; c=$1 # count for packets
while read -r host ; do
(sleep $sleep;ping -s $host 56 $c >/dev/null) &
pid=$! ; wait $pid
if [ $? -eq 0 ] ; then
PL=$(i=1;while [ $i -le $c ] ; do sleep $sleep;ping -s $host 56 $c ;((i++));done)
echo "$PL"|nawk -F, -v c=$1 -v host=$host -v sleep=$sleep '/packets/{sub("% packet loss","",$3)}{t+=$3}
END{if(t>50*c){print "ping problem in \""host"\" !!\nping loss \"%"t" of %"100*c"\" for at "c" packet tries in "sleep" seconds intervals\n"}
else {print "\""host"\" is alive with \"%"t" of %"100*c" loss rate\" at "c" packet tries in "sleep" seconds intervals\n"}}'
else echo -e "ping failed while sending 'echo_request(s)' to \"$host\"\n\
check!! host access (/network or firewall or route(ing) settings/) or \ncheck!! resolution (/hosts/dns/nsswitch)!!\n\
or \ncheck!! be sure host is power up or \ncheck!! is ping enabled in o.s or switch(s) or router(s)\n"
fi;done<$2

regards
ygemici
This User Gave Thanks to ygemici For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Ping test sends mail when ping fails

help with bash script! im am working on this script to make sure my server will stay online, so i made this script.. HOSTS="192.168.138.155" COUNT=4 pingtest(){ for myhost in "$@" do ping -c "$COUNT" "$myhost" &&return 1 done return 0 } if pingtest $HOSTS #100% failed... (4 Replies)
Discussion started by: mort3924
4 Replies

2. Shell Programming and Scripting

How to get reason for ping failure using perls Net::Ping->new("icmp");?

Hi I am using perl to ping a list of nodes - with script below : $p = Net::Ping->new("icmp"); if ($p->ping($host,1)){ print "$host is alive.\n"; } else { print "$host is unreacheable.\n"; } $p->close();... (4 Replies)
Discussion started by: tavanagh
4 Replies

3. Linux

Ping check failed from Nagios master server on windows hosts in the same subnet

Hello All, We have added a windows host and its config files to Nagios master server and wanted to do a ping check alone at the moment however, the nagios master server identifies the host in its GUI and immediately disappears can anyone let me know the right approach to this one, We want to... (2 Replies)
Discussion started by: lovesaikrishna
2 Replies

4. Shell Programming and Scripting

Animation Ping on Solaris Like Cisco Ping

Hi, I develop simple animation ping script on Solaris Platform. It is like Cisco ping. Examples and source code are below. bash-3.00$ gokcell 152.155.180.8 30 Sending 30 Ping Packets to 152.155.180.8 !!!!!!!!!!!!!.!!!!!!!!!!!!!!!. % 93.33 success... % 6.66 packet loss...... (1 Reply)
Discussion started by: gokcell
1 Replies

5. Shell Programming and Scripting

[ASK] How to check whether ipv4 or ipv6 and ping those IP

I have perl script that I use to check and ping a list of ip, The problem is, I didnt understand how to ping ipv6 on perl, Could I use Ping::External??And how could I get the ping result (reply or not)? This is my code #!/usr/bin/perl -- use Net::Ping; use Data::Validate::IP; use... (3 Replies)
Discussion started by: franzramadhan
3 Replies

6. UNIX for Dummies Questions & Answers

ping is blocked hwo to check connection

Hi How to check connection with another IP/Server not using ping? Thanks (5 Replies)
Discussion started by: miojamo
5 Replies

7. Solaris

How to check disk broken

Dear all, I have system that have 2 disk, and 1 off disk is broken, how can I check if the disk is broken or other problem. I'm using Solaris 10 x86. Thank you, Best Regards, Heru (4 Replies)
Discussion started by: heru_90
4 Replies

8. Debian

./configure is broken - /lib/cpp fails sanity check

Hi, I first wanted to install my NIC drivers but it said: Makefile:62: *** Linux kernel source not found. Stop. So I installed the kernel source: linux-source-2.6.18_2.6.18.dfsg.1-13etch5_all.deb 1) cd /usr/src 2) -xjvf linux-source.2.6.18.extension (forget what it was) 3) ln -s... (12 Replies)
Discussion started by: Virtuality
12 Replies

9. UNIX for Advanced & Expert Users

Broken

Ok i am running Linux, or rather was. I can not longer do anything. This was a dns server amoungst other things. It will no longer boot. I have used a startup disk, but how can i recover the OS? I need help and urgently. Please someone thanks (3 Replies)
Discussion started by: ollyparkhouse
3 Replies
Login or Register to Ask a Question