Check ping response from a list of servers using for loop in Unix/Linux ?

In this post, we will check the ping response from the list of servers using for loop in Unix/Linux.

Lets see below script which will check the ping response from different server names saved in serverlist file.

Script to check ping response

#!/bin/sh
CWD=`pwd`
ERRFILE="$CWD/error.log"
COLLECTFILE="$CWD/standard.log"
SRVLIST="$CWD/serverlist"

for SERVER in `cat $SRVLIST`
do
ping -c 1 $SERVER 1>/dev/null 2>&1
STAT=$?
if [ $STAT -eq 0 ];
then
echo "Ping success for $SERVER" >> $COLLECTFILE
else
echo "Ping failed for $SERVER" >> $ERRFILE
fi
done
5 1 vote
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments