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
# 8  
Old 01-04-2012
@ 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.
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
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
Code:
#./network_hosts it comes up with the message as
 "0403-057 Syntax error at line 14 : `fi' is not expected."

Please assist
# 9  
Old 01-04-2012
you have no instruction inside the if...fi group

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
Code:
#!/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
This User Gave Thanks to Skrynesaver For This Post:
# 10  
Old 01-05-2012
My bad :-(
Thanks Skrynesaver. It works fine now
Login or Register to Ask a Question

Previous Thread | Next Thread

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
Login or Register to Ask a Question