Network script for ping status


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Network script for ping status
# 8  
Old 09-10-2014
Perhaps you can map IPs to host names, like this
Code:
hst=`getent hosts "$i" | awk '{print $2}'`
echo "IP=$ip host="$hst

?
# 9  
Old 09-10-2014
I like MadeInGermany's idea of doing a host name lookup as this will involve less maintenance of your script, but it would involve ensuring all these machines are entered in the hosts file.

But if your trying to associate two lists as a learning exercise you could tackle it like this:

Code:
IP=( 
  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 )
BN=( 
    TIRUNELVELIUNITI TIRUNELVELIUNITII TIRUNELVELICAB  TENKASI
    KOVILPATTI       TUTICORIN         THIRUCHENDURE   SRIVAIKUNDAM
    VALLIOOR         NAGERCOILUNITI    NAGERCOILUNITII THUCALAY
    KUZHITHURAI      SANKARANKOIL      CHERANMAHADEVI  AMBAI )

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((i=0;i<${#IP[@]};i++))
          do
              echo ping -c 1 -W 1 ${IP[i]}
              if ping -n 1 ${IP[i]} 2>&1 2>&1 | egrep -q "unreachable|100%"
              then
                 [ $REPLY -eq 2 ] && let CNT=CNT+1 && list="$list\n${BN[i]} ${IP[i]}"
              else
                 [ $REPLY -eq 1 ] && let CNT=CNT+1 && list="$list\n${BN[i]} ${IP[i]}"
              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

This User Gave Thanks to Chubler_XL For This Post:
# 10  
Old 09-10-2014
I think you are genious chubler . 100 crores of thanks to you.
I have another question,please I want to add Branchcode(BC) also with ipaddress(IP) and BranchNames(BN) in output.


[code]IP=(
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 )

BC=(753 74P 74U 666
667 74W 74Z 32A
74G 754 7251 74S
300 74H 32B 74E)

BN=(
TIRUNELVELIUNITI TIRUNELVELIUNITII TIRUNELVELICAB TENKASI
KOVILPATTI TUTICORIN THIRUCHENDURE SRIVAIKUNDAM
VALLIOOR NAGERCOILUNITI NAGERCOILUNITII THUCALAY
KUZHITHURAI SANKARANKOIL CHERANMAHADEVI AMBAI )



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.

753 TIRUNELVELIUNITI 10.66.1.133

74P TIRUNELVELIUNITII 10.66.6.133

74U TIRUNELVELIUNITCAB 10.66.7.133

666 TENKASI 10.66.0.133

667 KOVILPATTI 10.66.1.5

74WTUTICORIN 10.66.2.133

74Z THIRUCHENDURE 10.66.4.133

32A SRIVAIKUNDAM 10.66.3.133

74G VALLIOOR 10.66.5.133

754 NAGERCOILUNITI 10.66.2.5

7251 NAGERCOILUNITII 10.66.3.5

74S THUCALAY 10.66.7.5

300 KUZHITHURAI 10.66.0.5

74H 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.

32B CHERANMAHADEVI 10.66.4.5

74E AMBAI 10.66.5.5

Last edited by kannansoft1985; 09-10-2014 at 11:40 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