Created
July 1, 2013 06:37
-
-
Save davidgao/5898785 to your computer and use it in GitHub Desktop.
just a dirty hosts refreshing script
This file contains 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/bash | |
#skip empty or comment lines | |
function host_filter { | |
while read line; do | |
echo $line | grep -Ev "^($|#)" | |
done | |
} | |
#pick second part as hostname | |
function host_pickname { | |
while read entry; do | |
echo $entry | awk '{print $2}'; | |
done | |
} | |
#really perform lookup and tidy up | |
function host_lookup { | |
while read name; do | |
#for ipv6 | |
#add=`nslookup -q=aaaa $name | grep AAAA | awk '{print $5}'` | |
#for ipv4 | |
add=`nslookup $name | grep "Address" | grep -v "#" | head -n1 | awk '{print $2}'` | |
echo $add $name | |
done | |
} | |
host_filter | host_pickname | host_lookup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment