summaryrefslogtreecommitdiff
path: root/remove-known-host.sh
blob: 9aecb8e7719030d29f48be254b45dd830aed1442 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash

if [ -z "$1" ]; then
  echo "$0 <host>"
  exit 1
fi

TMP=`host -t A "$1" | grep -v "has no"`
IP=`echo "$TMP" | awk '{ print($4) }'`
HOST=`echo "$TMP" | awk '{ print($1) }'`

TMP=`host -t AAAA "$1" | grep -v "has no"`
IP6=`echo "$TMP" | awk '{ print($5) }'`
HOST6=`echo "$TMP" | awk '{ print($1) }'`

if [ "$HOST6" = "$HOST" ]; then
  HOST6=""
fi
SHORT="$1"
if [ "$SHORT" = "$HOST" ] || [ "$SHORT" == "$HOST6" ]; then
  SHORT=""
fi


for name in $IP $IP6 $HOST $HOST6 $SHORT; do
  ssh-keygen -f "/home/rhadmin/.ssh/known_hosts" -R "$name"
done

exit 0