Created
September 28, 2012 15:08
-
-
Save tykling/3800422 to your computer and use it in GitHub Desktop.
hosts file to bind zone file
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/sh | |
while read line; do | |
ip=$(echo $line | cut -d " " -f 1); | |
hosts=$(echo $line | cut -d " " -f 2-); | |
zone=$(echo $hosts | tr " " "\n" | awk '{print length"\t"$0}'|sort -n|cut -f2- | head -1); | |
echo "processing zone: $zone (ip $ip - hosts $hosts)"; | |
echo "\$ORIGIN $zone." > $zone.db; | |
echo "\$TTL 1h" >> $zone.db; | |
echo "$zone. IN SOA ns.$zone. username.$zone. ( 2007120710; 1d; 2h; 4w; 1h )" >> $zone.db; | |
for host in $hosts; do | |
if [ "$host" = "$zone" ]; then | |
echo "@ A $ip" >> $zone.db; | |
else | |
echo "$host A $ip" >> $zone.db; | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment