Visit Our UNIX and Linux User Community


Ping the hostname of many servers using a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ping the hostname of many servers using a script
# 1  
Old 01-03-2012
Ping the hostname of many servers using a script

Hi

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.
# 2  
Old 01-03-2012
Show us what you've done so far... Where are your problems?
# 3  
Old 01-03-2012
Hi,

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.:

Code:
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

see ya
fra
This User Gave Thanks to frappa For This Post:
# 4  
Old 01-03-2012
What is the problem exactly, ping takes a -c <count> modifier to exit after count packets so if you have a file with all the hostnames in it.
Code:
for host in $(cat network_hosts);do 
   if [ ! "$( ping -c 1 $host 2>/dev/null| grep '1 received' )" ] ; then 
      echo "$host is unresponsive"
   fi
done

This User Gave Thanks to Skrynesaver For This Post:
# 5  
Old 01-04-2012
Hi

Below is the file containing the hostnames of all the servers
Code:
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

All the servers are live except cbdodbfs2.standardchartered.co.in as we have shutdown this lpar.

Please suggest me a script which will tell that "cbdodbfs2.standardchartered.co.in" is not alive and the rest are alive.
# 6  
Old 01-04-2012
Hi,

how should the script report the downed servers? (email, log file, a message on the screen,...)
# 7  
Old 01-04-2012
@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.

Previous Thread | Next Thread
Test Your Knowledge in Computers #57
Difficulty: Easy
In a Database Management System (DBMS), the content and the location of the data is defined by the meta data.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to ping multiple servers

Hi I did the following script to ping multiple servers, but I keep on receiveing duplicate emails for one server that is down: #!/bin/bash date cat /var/tmp/servers.list | while read output do ping -c 1 "$output" > /dev/null if ; then echo "node $output is up" else ... (10 Replies)
Discussion started by: fretagi
10 Replies

2. Shell Programming and Scripting

Ping script to list of servers

Hi Friends, I have experience in redhat/ Ubuntu OS, but I am very new to solaries os. my servers OS is Oracle Solaris 10 8/11 s10x_u10wos_17b X86. I have a file contains 200 servers IPs one by one. now I want a script to chaeck which IPs are pinging, not pingning. I... (8 Replies)
Discussion started by: kumar85shiv
8 Replies

3. Shell Programming and Scripting

Script to Ping Servers

Hey, It's me again! Still trying to learn to become a better scripter on the job :) New challenge for assistance, if anyone cares to help, and its two parted! First part, I wanted to create a script at work that would ping a server that was supplied in an argument, then a count (amount of times)... (5 Replies)
Discussion started by: gkelly1117
5 Replies

4. Shell Programming and Scripting

Need bash script to ping the servers and rename the output file each time the script is ran

HI, I have a file serverlist in that all host names are placed. i have written a small script #./testping #! /bin/bash for i in `cat serverlist` do ping $i >> output.txt done so now it creates a file output.txt till here fine.. now each time i run this script the output file... (4 Replies)
Discussion started by: madhudeva
4 Replies

5. UNIX for Advanced & Expert Users

ping by hostname not working

anyone ever seen this problem: I can ping the server by IP address but I can't by hostname. nslookup is working and dns query is ok. # nslookup mwxnsb24 Server: 10.11.49.206 Address: 10.11.49.206#53 Name: mwxnsb24 Address: 10.10.58.175 # ping... (8 Replies)
Discussion started by: linuxgeek
8 Replies

6. AIX

Ping by hostname

Hello everyone I have a partition with a problem with ping. If I do a ping by ip for example ping 1.1.1.1 I got no problem but If I ping by hostname for example ping partition1 take almost a minute to respond me. I have Aix 5.3 and I have another 19 partitions with no problem. The only... (5 Replies)
Discussion started by: lo-lp-kl
5 Replies

7. Solaris

Can't ping using hostname on Solaris 10

I recently installed Solaris 10 on my Sun workstation. I cannot ping using hostname from another computer on the same network. But I can ping using the IP address. Also I can ping other systems using their hostnames. Can anyone give some information regarding how to resolve this issue. (4 Replies)
Discussion started by: alpha123
4 Replies

8. Solaris

cannot ping by hostname

Hi All, My current setup is: 1x Windows Server (Windows 2000 server) 1x Unix Server 2x Windows machine 3x Unix Terminals (Hostnames = A, B and C) Problem The problem iam having is Unix terminal C cannot be ping across by Unix terminal A or B or Unix server by using the hostname. Unix... (1 Reply)
Discussion started by: tlee
1 Replies

9. UNIX for Advanced & Expert Users

script to ping servers

Hi , I would like to automate a script to ping all the unix servers perodically thru cronjob. Is there any script out there? If so Please give me. Thanks in advance. (2 Replies)
Discussion started by: sriny
2 Replies

10. AIX

Script to ping servers in a file

I would like to ping a list of servers in a text file. Can anyone help? (1 Reply)
Discussion started by: gbarkhor
1 Replies

Featured Tech Videos