ping hosts from config file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ping hosts from config file
# 1  
Old 01-26-2008
ping hosts from config file

Hello,

I have config files for my storage where file systems are exported to lots of hosts as root.

I need to write a script in ksh to somehow filter these hosts from the file and ping those and if pingable than do nothing but if not pingable than send an alert to a log file which says:

host xyz not pingable:

file looks like as follows:

/vol/vol1/apps_data01 -sec=sys,rw,root=unixsrv1:unixsrv2:unixsrv3:mercury:mercury01:sunprd01:sunprd02
/vol/vol1/apps_data02 -sec=sys,rw,root=unixsrv1:unixsrv2:unixsrv3:mercury:mercury01:sunprd01:sunprd02
/vol/vol1/apps_data03 -sec=sys,rw,root=unixsrv1:unixsrv2:unixsrv3:mercury:mercury01:sunprd01:sunprd02
/vol/vol1/apps_data04 -sec=sys,rw,root=unixsrv1:unixsrv2:unixsrv3:mercury:mercury01:sunprd01:sunprd02
.
.
/vol/vol1/apps_data45 -sec=sys,rw,root=unixsrv1:unixsrv2:unixsrv3:mercury:mercury01:sunprd01:sunprd02:hpprod07:ibmprod43


I have about 26 of these files on each storage host where hosts names are same and different:

I do not how to capture host names from the file and complete this logic.

Appreciate your help on this.
# 2  
Old 01-29-2008
Java

Not the most efficient solution (ideally you'd pull out all the hostnames, from all the lines then remove duplicates) but you can do this:
Code:
#!/bin/sh
while read line
do
  for hostname in `echo $line | cut -d '=' -f 2 | sed 's/:/ /g'`
  do
    if ! ping -s $hostname 1 1 > /dev/null
    then
      /bin/true
    else
      echo "host $hostname not pingable"
    fi
  done
done

usage: scriptname.sh < configfile.txt > logfile.txt

(Untested - you will probably need to debug a bit)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

How to copy a tar file on a series of remote hosts and untar it on those hosts?

Am trying to copy a tar file onto a series of remote hosts and untar it at the destination. Need to do this without having to do multiple ssh. Actions to perform within a single ssh session via shell script - copy a file - untar at destination (remote host) OS : Linux RHEL6 (3 Replies)
Discussion started by: sankasu
3 Replies

2. AIX

aix tcp wrappers hosts.allow hosts.deny?

hi all just installed the netsec.options.tcpwrapper from expansion pack, which used to be a rpm, for my aix 6.1 test box. it is so unpredictable. i set up the hosts.deny as suggested for all and allow the sshd for specific ip addresses/hostnames. the tcpdchk says the hosts allowed and... (0 Replies)
Discussion started by: wf201626
0 Replies

3. UNIX for Dummies Questions & Answers

Hosts file

What are the xid and cid numbers in a host file used for on solaris? If possible can I get a detailed link on the configuration of hosts file explaining xid and cid. :o (1 Reply)
Discussion started by: usm4n
1 Replies

4. Linux

Ping check failed from Nagios master server on windows hosts in the same subnet

Hello All, We have added a windows host and its config files to Nagios master server and wanted to do a ping check alone at the moment however, the nagios master server identifies the host in its GUI and immediately disappears can anyone let me know the right approach to this one, We want to... (2 Replies)
Discussion started by: lovesaikrishna
2 Replies

5. Solaris

able to ping all hosts but not able to traceroute any host

i am using solaris 10 and i am able to ping all the hosts but i am not able to traceroute any of them. how to fix this? (9 Replies)
Discussion started by: chidori
9 Replies

6. Red Hat

Can't ping on Fedora 10 affer config NAT iptables

Currently,i use Fedora 10 and get a follow trouble : My network: route(10.11.10.2/24)----eth0----(10.11.10.105/24)Fedora10(172.16.239.1/24)----vmnet0----(172.16.239.2/24)Virtual Machine XP2. I used : Vmware 6.5.1,Virtual Machine : Window XP SP2. , iptable 1.4.1.1 I set up static ip... (2 Replies)
Discussion started by: kideltn
2 Replies

7. Shell Programming and Scripting

Shell script that will compare two config files and produce 2 outputs 1)actual config file 2)report

Hi I am new to shell scripting. There is a requirement to write a shell script to meet follwing needs.Prompt reply shall be highly appreciated. script that will compare two config files and produce 2 outputs - actual config file and a report indicating changes made. OS :Susi linux ver 10.3. ... (4 Replies)
Discussion started by: muraliinfy04
4 Replies

8. Shell Programming and Scripting

parsing config file to create new config files

Hi, I want to use a config file as the base file and parse over the values of country and city parameters in the config file and generate separate config files as explained below. I will be using the config file as mentioned below: (config.txt) country:a,b city:1,2 type:b1... (1 Reply)
Discussion started by: clazzic
1 Replies

9. UNIX for Dummies Questions & Answers

HOSTS File

Hi All, I am to the UNIX world and want to know if I can specify a range of IP addresses instead of having to include one by one on the HOSTS file. Can I just say 127.20.1.1 to 127.20.1.156 ? Or the only way is to put one by one along with the machine name next to the IP ? THANKS (4 Replies)
Discussion started by: cymerman
4 Replies

10. UNIX for Dummies Questions & Answers

hosts.allow & hosts.deny

Hi! Im trying to use host.allow & host.deny to resrtic access to my sun machine, but it doesnt seem to work... I want to allow full access from certain IPīs (ssh,http,ftp,etc...) but deny all kind of conections from outsideworld, the way that im doing that is: hosts.allow ALL:127.0.0.1... (2 Replies)
Discussion started by: Sorrento
2 Replies
Login or Register to Ask a Question