#/bin/bash

# Run this script to generate bashrc for all roots in all nodes

### script to generate ssh-reachable nodes, $hosts
### list of hosts ################
cat /etc/hosts | awk 'NF==4 {print $4}' | uniq | sort > temp.dat
echo 192.168.1.10 > temp2.dat
cat temp.dat >> temp2.dat
hosts=$(cat temp2.dat | uniq)
rm -rf temp.dat temp2.dat temp2.dat
### end of list of hosts #########

rm -rf  hosttemp
for i in $hosts
	do
		checkping=$(ping -q -c1 -W 1 $i | awk 'NR==4 {print $4}')

		if [ $checkping -eq 0 ]
		then
			echo $i is not responding to ping after 1 second
		fi

		if [ $checkping -eq 1 ]
		then
			echo $i is responding to ping within 1 second
			echo $i >> hosttemp.dat
		fi
	done
hosts=$(cat hosttemp.dat | uniq)

rm -rf hosttemp.dat
### end of script to generate ssh-reachable nodes, $hosts


for i in $hosts
	do
		ssh -X -Y $i "/share/apps/local/bin/gen_bashrc.txt"
		echo gen_bashrc.txt has been executed in $i
	done

