The scripts that I am sharing are used to do the DB2 pureScale install on 'n' number of hosts. One of the issue is to have consistent /etc/hosts file on all nodes.
The input file is ip.txt similar to the previous posts.
Script to generate and copy hosts file to all hosts
#!/bin/bash if [[ $EUID -ne 0 ]]; then echo "This script must be run as root" 1>&2 exit 1 fi if [ $# -lt 1 ] ; then echo "Usage: $0" exit 1 fi function runrcmd () { expect -c " set timeout 2 spawn $1 expect eof { return ; } expect \"yes/no\" { send \"yes\r\" } expect \"*Password:*\" { send \"$rootpassword\r\" } expect \"(.*)\r\" " } SCHOME=./backup IPFILE=$SCHOME/ip.txt HOSTFILE=/tmp/hosts HOSTHEAD=$SCHOME/hosts.head LOGFILE= #################### Fix ip.txt ################### /usr/bin/dos2unix $IPFILE ############################################################### ############ Fix hosts file ################# sed -i /50000/d /etc/services cat $HOSTHEAD > $HOSTFILE while read a b c d do NM=${d%%.*} echo $b $d $NM >> $HOSTFILE done < $IPFILE ############################################# ############### Build server list from ip.txt ##### i=0 while read a b c d do SHORTNM=${d%%.*} servers[$i]=$b ((i++)) done < $IPFILE echo "server list " ${servers[@]} ################################################### ########## Copy hosts to each server ############## for ((i = 0; i < ${#servers[@]}; ++i)); do server=${servers[$i]}; echo Copy generated hosts file to $server runrcmd "/usr/bin/scp $HOSTFILE $server:/etc/hosts" done ###################################################
Download the script here.