Skip to content

Instantly share code, notes, and snippets.

@danmactough
Created September 30, 2014 14:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danmactough/0849c7355f97e8977230 to your computer and use it in GitHub Desktop.
Save danmactough/0849c7355f97e8977230 to your computer and use it in GitHub Desktop.
#!/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