Created
January 13, 2017 01:37
-
-
Save mohemohe/593bbf44bc703f5494cd722b35aa0f07 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 | |
| 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