Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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