Created
February 7, 2012 17:57
-
-
Save slumos/1760997 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/zsh | |
usage () { | |
echo "usage: ${0:t} [-f known_hosts] host..." | |
} | |
KNOWN_HOSTS="$HOME/.ssh/known_hosts" | |
expanded_hosts() { | |
case $(uname) in | |
Darwin) | |
echo -e "$1\t$(host $1 | awk '/address/ {print $4 "\t" $1}')" | |
;; | |
*) | |
echo -e "$1\t$(getent hosts $1)" | |
;; | |
esac | |
} | |
while getopts ':hf:' opt; do | |
case "$opt" in | |
f) | |
$KNOWN_HOSTS="$OPTARG" | |
;; | |
h|?) | |
usage | |
exit | |
;; | |
esac | |
done | |
if [[ $# -lt 1 ]]; then | |
usage | |
exit | |
fi | |
for arg in $*; do | |
hosts="$(expanded_hosts $arg)" | |
for h in ${=hosts}; do | |
ssh-keygen -f "$KNOWN_HOSTS" -R $h | |
done | |
ssh-keyscan -tdsa,rsa ${=hosts} >>"$KNOWN_HOSTS" 2>/dev/null | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use it with zsh parameter generation like:
But you could do this on BSD:
$ update-known-hosts.sh $(jot -w vdb-%03d 16)
Or this on Linux: :-(
$ update-known-hosts.sh $(printf 'vdb-%03d\n' $(seq 16))