From 8e72ec7a6c251eff03dc1612f4a7a17f6f68b1b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20Logerais=20=28Numericable=20-=20Ing=C3=A9nierie?= =?UTF-8?q?=20Syst=C3=A8me=29?= Date: Tue, 19 Nov 2013 17:32:05 +0100 Subject: [PATCH] Add lib for ssh with function ssh_clean_known_hosts --- libs/ssh.bash | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 libs/ssh.bash diff --git a/libs/ssh.bash b/libs/ssh.bash new file mode 100644 index 0000000..13ad104 --- /dev/null +++ b/libs/ssh.bash @@ -0,0 +1,18 @@ +#!/bin/bash + +function ssh_clean_known_hosts () +{ + if [ -z "$1" ] + then + echo "No arguments given. Cleaning ~/.ssh/known_hosts" + sed -i -e '/no hostip for proxy command/ d' ~/.ssh/known_hosts + else + hostname=$1 + ip=$(ssh admin dig +short $1) + echo "Removing host ${hostname} from ~/.ssh/known_hosts" + sed -i -e "/${hostname}/ d" ~/.ssh/known_hosts + echo "Removing ip ${ip} from ~/.ssh/known_hosts" + sed -i -e "/${ip}/ d" ~/.ssh/known_hosts + fi + +}