Visit The New, Modern Unix Linux Community


Ping script to list of servers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ping script to list of servers
# 1  
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 prepared the below script.

HTML Code:
 #!/bin/bash
#
#
while read line
do
        /usr/sbin/ping $line > /dev/null
        if [ $? == 0 ];
        then
        echo "$line is pinging"
        else
        echo "$line is not pinging"
        fi
done < ipreport.txt
~
But the problem is ...if the ip is pinging, script moving to another IP, if IP is not pinging, script is getting strucked and not moving to next line.


please suggest me.

Thanks
Siva
# 2  
Quote:
Originally Posted by kumar85shiv
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 prepared the below script.

HTML Code:
 #!/bin/bash
#
#
while read line
do
        /usr/sbin/ping $line > /dev/null
        if [ $? == 0 ];
        then
        echo "$line is pinging"
        else
        echo "$line is not pinging"
        fi
done < ipreport.txt
~
But the problem is ...if the ip is pinging, script moving to another IP, if IP is not pinging, script is getting strucked and not moving to next line.


please suggest me.

Thanks
Siva
Hello Siva,

You can use following command in place of using only ping.
Code:
/usr/sbin/ping -c5 $line > /dev/null

This will only check for 5 packets in ping and if all are successfully send/received it will be successful.
Let me know if this helps you.

Thanks,
R. Singh
# 3  
I added as you guided me ...

Code:
 #!/bin/bash
#
#
while read line
do
        /usr/sbin/ping -c5 $line > /dev/null
        if [ $? == 0 ];
        then
        echo "$line is pinging"
        else
        echo "$line is not pinging"
        fi
done < ipreport.txt


even then same output ....
if the ip is pinging then only script is moving to another ip, or else its not moving to another Ip.

my ipreport.txt file is looks like this

vi ipreport.txt

10.x.x.1
10.x.x.2
-
-
-
-
-
10.x.x.100
# 4  
Instead of
Code:
/usr/sbin/ping $line > /dev/null

try:
Code:
/usr/sbin/ping "$line" 1 > /dev/null

This will create a timeout of 1 seconds. So after 1 second it will give up. Change it to more seconds at will

Note: there should be a space between 1 and >
# 5  
You may want to run each ping in background to save some waiting time.
This User Gave Thanks to RudiC For This Post:
# 6  
yess....this is working out ...


Thank you very much
# 7  
How do you get the exit states from the bg pings?
I would rather google/download/compile fping

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #370
Difficulty: Medium
Bytecode instructions are processed by hardware and so they may be arbitrarily complex.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to find Error: rpmdb open failed on list of servers

Hello all, I have a task to patch red hat servers and some servers have a corrupted rpm database and return the error: Error: rpmdb open failed I know how to fix this when it occurs. What I'm hoping to do is scan a list of servers by IP and report back which server have this error. ... (6 Replies)
Discussion started by: greavette
6 Replies

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

3. Shell Programming and Scripting

List the IP address of list of servers

Hi I have a file containing server names and i can ssh to all these servers without password. Could any body suggest me how to list out IP address of all the servers? Now i am manually doing this, like ssh to each server and run "ifcong -a" command and copy the ipaddress to a excel sheet.... (5 Replies)
Discussion started by: kumar85shiv
5 Replies

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

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

6. Shell Programming and Scripting

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... (9 Replies)
Discussion started by: newtoaixos
9 Replies

7. UNIX for Advanced & Expert Users

Shell script to check the /etc/default/kbd file on a list of SUN servers

Hello, I want to create a shell script that would check the file "/etc/default/kbd" for the entry KEYBOARD_ABORT=alternate on a list of SUN Solaris servers. If this entry is not uncommented (without #) then I should get a message/error report for the host which does not have the setting... (3 Replies)
Discussion started by: mahive
3 Replies

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

9. UNIX for Advanced & Expert Users

want to mail a list of files in different servers

Hi All, I am running my script in crontab and it is generating a file everyday. And I have 10 different servers and i am running the same script in every server in crontab which generates a file in every server per day. I want to retrieve those files from each server everyday. I want to... (1 Reply)
Discussion started by: AshishK
1 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