#!/bin/sh -e

##########################################################################
#   Script description:
#       Remove a host from all known_hosts files
#
#   Arguments:
#       hostname with domain
#       
#   History:
#   Date        Name        Modification
#   2016-07-27  J Bacon     Begin
##########################################################################

usage()
{
    printf "Usage: $0 host.domain\n"
    exit 1
}


##########################################################################
#   Main
##########################################################################

if [ $# != 1 ]; then
    usage
fi

auto-root-check $0

host=$1

if ! echo $host | fgrep -q '.'; then
    printf "No domain name in $host.\n"
    exit 1
fi

short_host=${host%%.*}
ip=$(awk -v host=$host '$1 !~ "^#" && $2 == host || $3 == host { print $1 }' /etc/hosts)

set +e

# For root user
ssh-keygen -R $host
ssh-keygen -R $short_host
ssh-keygen -R $ip
exit
for user in $(cluster-users); do
    file=/home/$user/.ssh/known_hosts
    if [ -e $file ]; then
	ssh-keygen -R $host -f $file
	ssh-keygen -R $short_host -f $file
	ssh-keygen -R $ip -f $file
	chown $user $file
    fi
done
