#!/bin/bash

rm -rf $HOME/.ssh/known_hosts

TEMP_FILE="/tmp/known_hosts"
cat /etc/hosts | sed -n '/\# PLEASE/,/# DO/p' | egrep -v '#' > ${TEMP_FILE}
hosts="TEST"
while IFS= read -r line
do
	#echo "LINE: $line"
	NF=$(echo ${line} | awk -F" " '{print NF}')
	#echo "Number of fields: $NF"
	for((i=2; i<=$NF; i++)); do
		FIELD=$(echo ${line} | awk -F" " "{print \$$i}")
		hosts="${hosts} ${FIELD}"
	done
done < "${TEMP_FILE}"

for host in $hosts
do
	echo $host
	#ssh -o StrictHostKeyChecking=no $host
	lower_host=$(echo $host | tr [A-Z] [a-z])
	ssh-keyscan $lower_host -o StrictHostKeyChecking=no | grep ecdsa-sha2-nistp256 >> $HOME/.ssh/known_hosts
done
