Created
September 30, 2014 14:57
-
-
Save danmactough/0849c7355f97e8977230 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/bash | |
LINE=$1 | |
KNOWN_HOSTS=~/.ssh/known_hosts | |
usage() { | |
cat <<-EOM | |
Usage: ssh-purge-host <line no> | |
EOM | |
} | |
if test -z $LINE; then | |
usage | |
exit | |
fi | |
if ! test -e $KNOWN_HOSTS; then | |
echo "$KNOWN_HOSTS does not exist" | |
exit 1 | |
fi | |
MSG="$(sed -n "${LINE}p" $KNOWN_HOSTS | cut -d ' ' -f 1) removed" | |
sed -i '' "${LINE}d" $KNOWN_HOSTS | |
RESULT=$? | |
if test $RESULT -eq 0; then | |
echo $MSG | |
exit 0 | |
else | |
echo "Something went wrong" | |
exit $RESULT | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment