Friday, 12 April 2019

Ping test in a shell script

[root@abcd oracle]# vi  $HOME/iplist
192.168.1.1
192.168.1.2
192.168.1.3
192.168.1.4
192.168.1.5
~
~
:wq!
[root@abcd oracle]# vi ping.sh
#!/bin/bash

for i in $( cat $HOME/iplist )
do
ping -q -c2 $i > /dev/null

if [ $? -eq 0 ]
then
echo $i "Pingable"
else
echo $i "Not Pingable"
fi
done
~
~
:wq!
[root@abcd oracle]# sh ping.sh
192.168.1.1 Pingable
192.168.1.2 Not Pingable
192.168.1.3 Pingable
192.168.1.4 Not Pingable
192.168.1.5 Pingable
[root@abcd oracle]#

No comments:

Post a Comment