Network script for ping status


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Network script for ping status
# 1  
Old 09-03-2014
Question Network script for ping status

Actually I am using Red hat Linux 4.4 version.
I want to check the 16 client pc status of connection from server.Whether the connection is available or not.I tried to develop the shell script for this code.But It don't work properly.I am a self study learner.Please give me a shell script for this program which is suitable for Redhat Linux 4.4 version.Please help me to resolve this problem.

Here this are required fields,

One is Server Ip : 10.66.62.5

Next is, 16 Clients IP :
Code:
10.66.1.133  
10.66.6.133  
10.66.7.133   
10.66.0.133 
10.66.1.5     
10.66.2.133  
10.66.4.133  
10.66.3.133   
10.66.5.133   
10.66.2.5    
10.66.3.5    
10.66.7.5    
10.66.0.5    
10.66.6.5    
10.66.4.5    
10.66.5.5

I am expecting output like as,
Code:
Please select your choice [1-2] : 

1 . connections available and listing those ips
2 . connections not available and listing those ips

Please select your choice [1-2]: 1

14 connections are available

Ips are ,
10.66.6.133  
10.66.7.133   
10.66.0.133 
10.66.1.5     
10.66.2.133  
10.66.4.133  
10.66.3.133   
10.66.5.133   
10.66.2.5    
10.66.3.5    
10.66.7.5    
10.66.0.5    
10.66.6.5    
10.66.4.5   

Please Select your choice [1-2] : 2

2 connections are not available

Ips are,
10.66.1.133  
10.66.5.5


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data. Thanks

Last edited by vbe; 09-03-2014 at 09:35 AM..
# 2  
Old 09-03-2014
If you dont show us your code, how do you expect us to help you?

We cant just guess what you put in it... Show us the code and the output and we can help get it working...
# 3  
Old 09-04-2014
Question network ping status

Quote:
Originally Posted by vbe
If you dont show us your code, how do you expect us to help you?

We cant just guess what you put in it... Show us the code and the output and we can help get it working...
Actually I tried this below program which is in the correct sequence order of 16 client ip address from 192.168.1.3 to 192.168.1.19.But I questioned program I don't have an idea because it is not in the correct sequence order of ip address.I just want to ping from server to 16 client ip address.whether the connection is available or not. I'm expecting output like as,
*How many connections are available and list that ips.
*How many connections are not available and list that ips.

My tried program code:
Code:
#!/bin/bash

upcnt=0
downcnt=0
for ip in 192.168.1.{3..19}
do
   if ping -c 1 -W 1 $ip > /dev/null
   then
        let upcnt=upcnt+1
        uplist="$uplist\n    $ip"
   else
        let downcnt=downcnt+1
        downlist="$downlist\n    $ip"
   fi
done

printf "$upcnt ips are available:$uplist\n"
printf "$downcnt ips are not available:$downlist\n"

Please If you have an idea , Please give me a shell script for my questioned program.

Last edited by Franklin52; 09-04-2014 at 02:40 PM.. Reason: Please use code tags
# 4  
Old 09-04-2014
So - what's not working correctly? Are those addresses pingable one by one from the command line? And, in your 10.66... example, what is the subnet mask ? Again, are those pingable?
# 5  
Old 09-04-2014
Perhaps something like this, it's not interactive, however it achieves what you want with test FQDN's that you can change to your IP's.


Code:
jaysunn-> cat ping_test.sh 
#!/bin/bash

ServerList='www.google.com www.bing.com www.yahoo.com www.fakesite1111.com'

for i in ${ServerList} ; do



    echo "-------------------------------------------------------------"
    echo ${i}
    echo "-------------------------------------------------------------"
    ping -c 1 ${i} |grep '1 packets transmitted'
    if [ $? == 0 ]
        then
            echo "Ping is ok"
        else
            echo "!!ping Bad!!"
    echo "-------------------------------------------------------------"
            exit 1
    fi
done

OUTPUT:
Code:
jaysunn-> bash ping_test.sh 
-------------------------------------------------------------
www.google.com
-------------------------------------------------------------
1 packets transmitted, 1 packets received, 0.0% packet loss
Ping is ok
-------------------------------------------------------------
www.bing.com
-------------------------------------------------------------
1 packets transmitted, 1 packets received, 0.0% packet loss
Ping is ok
-------------------------------------------------------------
www.yahoo.com
-------------------------------------------------------------
1 packets transmitted, 1 packets received, 0.0% packet loss
Ping is ok
-------------------------------------------------------------
www.fakesite1111.com
-------------------------------------------------------------
ping: cannot resolve www.fakesite1111.com: Unknown host
!!ping Bad!!
-------------------------------------------------------------
[~]

# 6  
Old 09-04-2014
How about this:

Code:
IPS="10.66.1.133  10.66.6.133  10.66.7.133  10.66.0.133
     10.66.1.5    10.66.2.133  10.66.4.133  10.66.3.133
     10.66.5.133  10.66.2.5    10.66.3.5    10.66.7.5
     10.66.0.5    10.66.6.5    10.66.4.5    10.66.5.5"

printf "1. connections available and listing those ips\n"
printf "2. connections not avialble and listing those ips\n"
while true
do
    printf "\n\nPlease select you choice [1-2]: "
    read
    printf "\n"
    CNT=0
    list=""
    case $REPLY in
       1|2) for ip in $IPS
          do
              if ping -c 1 -W 1 $ip 2>&1 2>&1 | egrep -q "unreachable|100%"
              then
                 [ $REPLY -eq 2 ] && let CNT=CNT+1 && list="$list\n$ip"
              else
                 [ $REPLY -eq 1 ] && let CNT=CNT+1 && list="$list\n$ip"
              fi
          done
          [ $REPLY -eq 1 ] && printf "$CNT connections are available\n\nIPs are,$list"
          [ $REPLY -eq 2 ] && printf "$CNT connections are not available\n\nIPs are,$list" ;;
       *) printf "Invalid choice\n\n"
          break
       ;;
    esac
done

Note: the parameters and output format of ping can vary from OS to OS for Redhat Linux you have -c 1 -W 1 parameters for 1 ping with 1 sec timeout. On another system it could be -n 1 -w 1.

For failed output we are looking for "100%" or "unreachable" (as in "100% packet loss" or "destination is unreachable").

Last edited by Chubler_XL; 09-04-2014 at 06:19 PM..
These 2 Users Gave Thanks to Chubler_XL For This Post:
# 7  
Old 09-10-2014
Excellent This is I want,Superbly working Well Done Good Job!Crores Of Thanks to Chubler_XL.I learned the above code bit by bit.Please explain the above code.

I have one question , I want to merge the branch name with that ip address in ouptut. Each ip address have a name.Below I have mentioned the branch name for IP Address.Please check it.

IPS="10.66.1.133 10.66.6.133 10.66.7.133 10.66.0.133
10.66.1.5 10.66.2.133 10.66.4.133 10.66.3.133
10.66.5.133 10.66.2.5 10.66.3.5 10.66.7.5
10.66.0.5 10.66.6.5 10.66.4.5 10.66.5.5"


BranchNames="TIRUNELVELIUNITI TIRUNELVELIUNITII TIRUNELVELICAB TENKASI

KOVILPATTI TUTICORIN THIRUCHENDURE SRIVAIKUNDAM

VALLIOOR NAGERCOILUNITI NAGERCOILUNITII THUCALAY

KUZHITHURAI SANKARANKOIL CHERANMAHADEVI AMBAI"

I am expecting Output like as,

Please Select your choice[1-3]: 1
1.How many branchnetwork connections are available .
2.How many branch network connections are not available.
3.Exit

14 branch network connections are working fine.

TIRUNELVELIUNITI 10.66.1.133

TIRUNELVELIUNITII 10.66.6.133

TIRUNELVELIUNITCAB 10.66.7.133

TENKASI 10.66.0.133

KOVILPATTI 10.66.1.5

TUTICORIN 10.66.2.133

THIRUCHENDURE 10.66.4.133

SRIVAIKUNDAM 10.66.3.133

VALLIOOR 10.66.5.133

NAGERCOILUNITI 10.66.2.5

NAGERCOILUNITII 10.66.3.5

THUCALAY 10.66.7.5

KUZHITHURAI 10.66.0.5

SANKARANKOIL 10.66.6.5

Please Select your choice[1-3]: 2
1.How many branchnetwork connections are available .
2.How many branch network connections are not available.
3.Exit

2 branch network connections are not available.

CHERANMAHADEVI 10.66.4.5

AMBAI 10.66.5.5

Last edited by kannansoft1985; 09-10-2014 at 01:58 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ping the service with out port number on remote network

I got the service status through nc on remote network but 2 services doesn't have port number.how to get the other 2 services status with out port number .pls provide the solution to me. I need to develop with is in a script (2 Replies)
Discussion started by: kannansoft1985
2 Replies

2. AIX

Able to ping the server but not able to login through putty it says network timeout

Able to ping the server but not able to login through putty it says network timeout Please assist (3 Replies)
Discussion started by: Vishal_dba
3 Replies

3. Red Hat

RHEL4 on VM cannot get status network link down

Hi All, RHEL4 on VM cannot get status network link down. when I unplug network cable. - ESX found interface down - but VM RHEL4 not detect that !, It show still up (mii-tool) Please help share you idea for my case. ESXi 5.1.0, RHEL4 Thank you, (3 Replies)
Discussion started by: arm_naja
3 Replies

4. Solaris

Solaris 10 - ping network issue

Hi, I'am begineer in this OS. I've installed it few days ago only to perform project "Managing users in Solaris". I have to create two virtual systems in eg. vmware , connect them and eg. rlogin from user1/machine1 to user2/machine2, give them some permissions to write read etc (this is... (1 Reply)
Discussion started by: michael.pelc
1 Replies

5. IP Networking

ping to different network in linux

Hi all, please help solving my small issue below is the configuration I have 3 systems sytem1 -------- system 2 ----------system 3 system 1 : 10.255.1.4 & default gw 10.255.1.55 system2 : ip 1 : 10.255.1.55 , ip 2: 10.255.2.1 system 3 : ip : 10.255.2.3 on system 2 : ... (4 Replies)
Discussion started by: Gopi Krishna P
4 Replies

6. IP Networking

Able to ping server's private network

Hi guys, I'm in the progress of setting up a private network in our Sun solaris platform. Existing ip: 172.16.102.101 New private ip: 192.168.2.3 Netmask is the same for both private & public 255.255.255.0 After setting up the ip, I'm able to ping this private ip address from our... (3 Replies)
Discussion started by: *Jess*
3 Replies

7. UNIX for Advanced & Expert Users

ping all the machines in the network

Is there any option for the utility "ping" , which can ping all the machines in the network? (5 Replies)
Discussion started by: praveen_b744
5 Replies

8. UNIX for Dummies Questions & Answers

NIC The Status Down but I can ping the localhost??!!

Hello, hi guys I don't know what is the problem with my NIC I can ping the Localhost (LOOPBACK) but when I run a scripts to check the NIC statuse it's shown the NIC DOWN sooo what could be the problem and what is the best way to start trouplshooting the NIC in SUN-SOLARIS. Regards, Karim ... (3 Replies)
Discussion started by: geoquest
3 Replies

9. Shell Programming and Scripting

Multiple Network Card Status Script

I have multiple Sun Solaris 8 systems running multiple network cards. (Mix of quad and gig cards.) What I would like to do is create a monitor script to ensure high availability of these cards. Has anyone ever had a situation like this? I was thinking of using the ping command, but am... (1 Reply)
Discussion started by: Krusty
1 Replies

10. UNIX for Advanced & Expert Users

Network Status

Hi, My system ( Solaris 2.6, Entrerprise 250 ) shows lot of connections in TIME_WAIT status against service localhost.8007 and localhost.45221 What are these services and where can I get the cross references. I have checked up in /etc/services and there is no such entry. Infact... (5 Replies)
Discussion started by: shibz
5 Replies
Login or Register to Ask a Question