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
```text
and
```
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.
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
# ./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)
# 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
ygemici,
please also include this statement passed within your script provided whenever i get ping broken
i.e If ping response is not responding(i.e when hostname is not alive) then this cmd to be executed :
opcmsg object=PING a=PING msg_grp=win-ping severity=critical msg_text="PING BROKEN on $line"
#!/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) {system("opcmsg object=PING a=OS msg_grp=OpC severity=critical msg_text=\"PING BROKEN on "host"\"")
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
you are right , ping test takes long time..i modified and defined some defaults(for exa ping test about send 4 echo packet check in script)..
now you can give a ping try count for first parameter and then see the results..(actually 50 try requires more times but if you want to test in long time period then maybe you must specify 50 100 or 200 or more than parameter..)
so in script , ping tries transmit packets to target with 2 seconds intervals and 4 packets
first(prestart control) ping test takes about four seconds(normally about 1 second per packet or under 1 second ,, of course it may vary depending on various factors however) if target is avaliable and must must not be resulotion problem [ default timeout is 20 second ].but we defined packet size then it takes about 10 seconds + 4*1 second (per packet) = about 14 seconds.
lets look belows.
# if you dont have access to host..(some waits target host is non-accessable)
# time ping -s 192.168.56.112 56 4
PING 192.168.56.112: 56 data bytes
----192.168.56.112 PING Statistics----
4 packets transmitted, 0 packets received, 100% packet loss
real 0m13.069s
user 0m0.020s
sys 0m0.043s
# if you have access to host..(no wait target host is accessable)
# time ping -s 192.168.56.111 56 10
PING 192.168.56.111: 56 data bytes
64 bytes from solaris (192.168.56.111): icmp_seq=0. time=1.42 ms
64 bytes from solaris (192.168.56.111): icmp_seq=1. time=0.704 ms
64 bytes from solaris (192.168.56.111): icmp_seq=2. time=0.722 ms
........................
64 bytes from solaris (192.168.56.111): icmp_seq=9. time=0.795 ms
----192.168.56.111 PING Statistics----
10 packets transmitted, 10 packets received, 0% packet loss
round-trip (ms) min/avg/max/stddev = 0.381/0.8182/1.42/0.260
real 0m9.092s
user 0m0.027s
sys 0m0.051s
at the now,you must you can try and use to a specifying parameter with new script..
for example
# ./testping.sh 2 hostlist
this means that you want to try for Number of 4-pack counts[this is defaul in script] * 2 count..
#!/usr/bin/bash
## justdoit ## ping test on SunOS ##
if [ $# != 2 ] ; then echo "usage $0 'packetcount' hostlistfile" ; exit 0 ; fi
if [[ $(echo $1|grep [^0-9]) ]] ; then echo "first parameter '$1' is not digit!!";exit 1;fi
sleep=2 ; c=$1 ; control=4 ; # count for packets
while read -r host ; do
printf "%s" "testing access to $host ...? "
(sleep $sleep;ping -s $host 56 $control > /dev/null 2>&1) &
pid=$! ; wait $pid
if [ $? -ne 0 ] ; then
printf "%s\n" "FAIL!! "
else
>tmppg
printf "%s\n" "SUCCESS "
## pinging try ##
printf "%s" "pinging try "
for((j=0;j<$c;j++)); do printf "%c" ".";sleep $sleep; ping -s $host 56 $control >>tmppg;done;
printf "%s\n" " OK"
nawk -F, -v c=$1 -v host=$host -v sleep=$sleep '/packets/{sub("% packet loss","",$3)}{t+=$3}
END{if(t>50*c) {system("opcmsg object=PING a=OS msg_grp=OpC severity=critical msg_text=\"PING BROKEN on "host"\"");
print "ping problem in \""host"\" !!\nping loss \"%"t" of %"100*c"\" for at "c" packet tries in "sleep" seconds intervals"}
else {print "\""host"\" is alive with \"%"t" of %"100*c" loss rate\" at "c" packet tries in "sleep" seconds intervals"}}' tmppg
fi;echo;done<"$2"