Created
August 26, 2009 05:28
-
-
Save ohlol/175338 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
BACKUP_TS=`date +%Y%m%d%H%S` | |
if [ -z "$1" ] | |
then | |
echo "What host/IP?" | |
exit 1 | |
fi | |
DNS=`host $1 | grep 'has address' | sed -e 's/has address //' -e 's/ /|/' | tr '\n' '|'` | |
DNS=`echo $DNS | sed -e 's/^|//' -e 's/|$//'` | |
if [ -z "$DNS" ] | |
then | |
echo "Got bad/empty hostname or IP list! ($DNS)." | |
exit 1 | |
fi | |
echo "Backup in ~/.ssh/known_hosts.$BACKUP_TS" | |
cp ~/.ssh/known_hosts ~/.ssh/known_hosts.$BACKUP_TS | |
TMPFILE=`mktemp /tmp/known_hosts.XXXXXXXX` || (echo "Couldn't make temp file!" && exit 1) | |
cp ~/.ssh/known_hosts $TMPFILE | |
egrep -ve "($DNS)" $TMPFILE > ~/.ssh/known_hosts | |
rm -f $TMPFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment