Guest User

Untitled

a guest
Aug 14th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. # Find path to programmes that will be used.
  4. WGET=$(which wget 2> /dev/null)
  5. ECHO=$(which echo 2> /dev/null)
  6. NSUPDATE=$(which nsupdate 2> /dev/null)
  7. HOSTNAME=$(which hostname 2> /dev/null)
  8. IFCONFIG=$(which ifconfig 2> /dev/null)
  9. SED=$(which sed 2> /dev/null)
  10. GREP=$(which grep 2> /dev/null)
  11. CUT=$(which cut 2> /dev/null)
  12. HEAD=$(which head 2> /dev/null)
  13.  
  14. # If run from cron then the default path does not include /sbin
  15. if [ -z $IFCONFIG ]; then
  16. IFCONFIG="/sbin/ifconfig"
  17. fi
  18.  
  19. # Set default zone.
  20. ZONE="bws.local"
  21.  
  22. # Get host information
  23. host=$($HOSTNAME)
  24. ip=$($HOSTNAME -i)
  25. server="$($GREP nameserver /etc/resolv.conf | $CUT -f 2 -d ' ' | $HEAD -1)"
  26.  
  27. # Create nsupdate input file.
  28. $ECHO "server $server" > /tmp/nsupdate
  29. $ECHO "zone $ZONE." >> /tmp/nsupdate
  30. $ECHO "update delete $host. A" >> /tmp/nsupdate
  31. $ECHO "update add $host. 86400 A $ip" >> /tmp/nsupdate
  32. $ECHO "send" >> /tmp/nsupdate
  33.  
  34. # Update DNS.
  35. $NSUPDATE -v /tmp/nsupdate 2>&1
Add Comment
Please, Sign In to add comment