We have some 300 servers in the Data center and some of them are running with AIX and some of them are running with Solaris.
I need a script which can be run in one of the server and that script should ping the hostname of all the 300 servers.
Also the script should notify if any server is down.
Please assist in writing the script.
first thing that comes to mind is to use a simple configuration file that contains the name of all the servers to be pinged, one per line.
Then you could write a script that reads each line and for each hostname read it pings, like i.e.:
while read line
do
# one ping to the current hostname
ping -c 1 ${line} > /dev/null 2>&1
# get the exit code of ping command
RETVAL=$?
if [ ${RETVAL} -ne 0 ] ; then
# log error somewhere, send a mail to someone, etc.
fi
done < /path/to/config_file
@newtoaixos:
What is not ok with the script frappa offered to you? What is missing? What did not work? Did you try it? Did you try anything?
Additionally just scroll down to the bottom of this thread and you see some similar threads where people try to ping hosts.
@ frappa : A message on the screen should be fine.
@ Zaxxon : I don't have any knowledge on scripts. I have added the content of frappa's script to my network_hosts file. The below is the current output from the file.
root#cat network_hosts
frssit02.standardchartered.co.in
frssit01.standardchartered.co.in
cbspssit.standardchartered.co.in
cbspsuat.standardchartered.co.in
cbsappfs1.standardchartered.co.in
cbsappfs2.standardchartered.co.in
cbdodbfs2.standardchartered.co.in
while read line
do
# one ping to the current hostname
ping -c 1 ${line} > /dev/null 2>&1
# get the exit code of ping command
RETVAL=$?
if [ ${RETVAL} -ne 0 ] ; then
# log error somewhere, send a mail to someone, etc.
fi
done
When I give
#./network_hosts it comes up with the message as
"0403-057 Syntax error at line 14 : `fi' is not expected."
frappa was fairly clear in saying that the hostname list was a seperate file which was sent to the new file thus saving the following as checker.sh
#!/bin/bash
while read line
do
# one ping to the current hostname
ping -c 1 ${line} > /dev/null 2>&1
# get the exit code of ping command
RETVAL=$?
if [ ${RETVAL} -ne 0 ] ; then
echo $line is not responding
fi
done < $1
and calling it like this . checker.sh hostlist would return a list of failing servers