Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #!/usr/bin/with-contenv sh
  2. if [ ! -f /etc/dnsmasq-resolv.conf ]
  3. then
  4. cp -f /etc/resolv.conf /etc/dnsmasq-resolv.conf
  5. echo "nameserver 127.0.0.1" > /etc/resolv.conf
  6. fi
  7.  
  8. while ! ps -ef | grep -v grep | grep dnsmasq-resolv.conf
  9. do
  10. sleep 1
  11. done
  12.  
  13. while true
  14. do
  15. env_vars=$(env | grep ".*_NAME=" | cut -d= -f1 | tr '\n' ' ')
  16. echo "#Auto Generated - DO NOT CHANGE" > /tmp/hosts
  17. for env_var in $env_vars
  18. do
  19. link=${env_var%_NAME}
  20. domain=$(cat /etc/dnsmasq-resolv.conf | grep search | cut -d' ' -f2)
  21. nameserver=$(cat /etc/dnsmasq-resolv.conf | grep nameserver | head -1 | cut -d' ' -f2)
  22. ip=$(nslookup "${link}.${domain}" ${nameserver} | grep Address | tail -1 | cut -d: -f2 | cut -d' ' -f2)
  23. if [ -n "$ip" ]
  24. then
  25. echo "${ip} ${link}" >> /tmp/hosts
  26. else
  27. logger "ip ${link}.${domain} skipped, it didn't resolve."
  28. fi
  29. done
  30.  
  31. if ! diff /tmp/hosts /etc/hosts.links
  32. then
  33. cp -f /tmp/hosts /etc/hosts.links
  34. killall -HUP dnsmasq
  35. fi
  36.  
  37. sleep 30
  38. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement