Skip to content

Instantly share code, notes, and snippets.

@mohemohe
Created January 13, 2017 01:37
Show Gist options
  • Select an option

  • Save mohemohe/593bbf44bc703f5494cd722b35aa0f07 to your computer and use it in GitHub Desktop.

Select an option

Save mohemohe/593bbf44bc703f5494cd722b35aa0f07 to your computer and use it in GitHub Desktop.
#!/bin/zsh
cat ~/.ssh/conf.d/*/*.sshconf >! ~/.ssh/config
grep -ioE 'Host[nN]ame (.*.local)' ~/.ssh/config | uniq | sed 's/\(Host[nN]ame\) \(.*\)/\2/g' | sort | uniq | while read domain
do
check=`arp $domain 2> /dev/null`
if [[ $? = 0 ]]; then
ip=`echo $check | sed 's/.*(\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\)).*/\1/'`
regex='s/\(Host[nN]ame\) \('$domain'\)/\1 '$ip'/g'
sed -i '' "$regex" ~/.ssh/config
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment