#! /bin/bash ### script to generate ssh-reachable nodes, /share/tmp/ssh-reachable.dat ### list of hosts as recorded in /share/hosts ################ cat /share/hosts | awk '{print $2}' | uniq | sort > /share/tmp/temp.dat cat /share/tmp/temp.dat >> /share/tmp/temp2.dat hosts=$(cat /share/tmp/temp2.dat | uniq) echo 'hosts in the clusters as recorded in /share/hosts are' $hosts rm -rf /share/tmp/temp.dat /share/tmp/temp2.dat rm -rf /share/tmp/ssh-reachable.dat /share/tmp/ssh-reachable2.dat for i in $hosts do checkping=$(ping -q -c1 -W 1 $i | awk 'NR==4 {print $4}') if [ $checkping -eq 0 ] then dummy=dummy # echo $i is not responding to ping after 1 second fi if [ $checkping -eq 1 ] then dummy=dummy # echo $i is responding to ping within 1 second echo $i >> /share/tmp/ssh-reachable.dat number=$(echo $i | awk -F"c" '{print $2}') if [ -n "$number" ] then echo 192.168.1.$number >> /share/tmp/ssh-reachable2.dat fi fi done echo 'ssh-reachable hosts are' $(cat /share/tmp/ssh-reachable.dat)