The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Copy a file to multiple hosts sumsriva UNIX for Advanced & Expert Users 5 09-18-2007 03:42 AM
HOSTS File cymerman UNIX for Dummies Questions & Answers 4 01-19-2007 12:26 PM
Hosts.allow and hosts.deny huddlestonsnk UNIX for Dummies Questions & Answers 1 10-18-2006 11:34 AM
hosts.allow & hosts.deny Sorrento UNIX for Dummies Questions & Answers 2 08-18-2005 09:25 PM
dns and hosts file rmuhammad IP Networking 4 11-12-2003 02:46 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-26-2008
za_7565 za_7565 is offline
Registered User
  
 

Join Date: Nov 2007
Location: ON, Canada
Posts: 16
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 (permalink)  
Old 01-29-2008
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 921
Post

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)
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 07:14 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0