Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/with-contenv sh
- if [ ! -f /etc/dnsmasq-resolv.conf ]
- then
- cp -f /etc/resolv.conf /etc/dnsmasq-resolv.conf
- echo "nameserver 127.0.0.1" > /etc/resolv.conf
- fi
- while ! ps -ef | grep -v grep | grep dnsmasq-resolv.conf
- do
- sleep 1
- done
- while true
- do
- env_vars=$(env | grep ".*_NAME=" | cut -d= -f1 | tr '\n' ' ')
- echo "#Auto Generated - DO NOT CHANGE" > /tmp/hosts
- for env_var in $env_vars
- do
- link=${env_var%_NAME}
- domain=$(cat /etc/dnsmasq-resolv.conf | grep search | cut -d' ' -f2)
- nameserver=$(cat /etc/dnsmasq-resolv.conf | grep nameserver | head -1 | cut -d' ' -f2)
- ip=$(nslookup "${link}.${domain}" ${nameserver} | grep Address | tail -1 | cut -d: -f2 | cut -d' ' -f2)
- if [ -n "$ip" ]
- then
- echo "${ip} ${link}" >> /tmp/hosts
- else
- logger "ip ${link}.${domain} skipped, it didn't resolve."
- fi
- done
- if ! diff /tmp/hosts /etc/hosts.links
- then
- cp -f /tmp/hosts /etc/hosts.links
- killall -HUP dnsmasq
- fi
- sleep 30
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement