Advertisement
dantpro

QNAP NAS as NTP Server

Apr 2nd, 2014
980
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.13 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # http://forum.qnap.com/viewtopic.php?p=279111
  4. # http://forum.qnap.com/viewtopic.php?f=85&t=5417&p=36422
  5. # http://forum.qnap.com/viewtopic.php?f=24&t=55181&start=15#p279347
  6.  
  7. # Fix paths to "ntpdate" and "ntpd" (if necessary) and setup NTPd Daemon.  
  8. # (based on suggestion by schumaku in:
  9. #    http://forum.qnap.com/viewtopic.php?f=24&t=55181&start=15#p279223 )
  10. #
  11. # Written by Patrick Wilson
  12. #
  13. # Prerequisites: None
  14. #
  15. # Purpose:
  16. #
  17. # This script will use the upstream NTP Server (as set in the Admin WebUI),  and
  18. # determine the IP's addresses of the defined server.  It will then define these same
  19. # IP addresses as the upstream servers for the local NTPD server on the NAS.  
  20. #
  21. # These IP addresses are pulled from "nslookup" instead of using hardcoded IP addresses,
  22. # in order to prevent accidental DoS attacks against the defined NTP server address.  
  23. #
  24. # Extreme care has been taken in this script to ensure that only Busybox executables are used
  25. # and each function is called with explicit fully qualified filenames to ensure no poor interactions
  26. # with any Optware packages that may be present.
  27. #
  28. NTPSVR=`/sbin/getcfg NTP "NTP Server IP"`
  29. NTPSVR_IPS=`/usr/bin/nslookup $NTPSVR | /bin/sed 's/[^0-9. ]//g'| /usr/bin/tail -n 1| /bin/awk -F " " '{print $1" "$2" "$3}'`
  30.  
  31. NTPSVR1=`echo $NTPSVR_IPS | /bin/cut -d " " -f 1`
  32. NTPSVR2=`echo $NTPSVR_IPS | /bin/cut -d " " -f 2`
  33. NTPSVR3=`echo $NTPSVR_IPS | /bin/cut -d " " -f 3`
  34.  
  35. echo The Upstream NTP Server - IP Addresses for this system are: $NTPSVR1 $NTPSVR2 $NTPSVR3
  36.  
  37. #
  38. # Enable NTPD
  39. #
  40. /sbin/setcfg NTP "Use NTP Server" TRUE
  41. /sbin/setcfg NTP "Enable NTP Server" TRUE
  42.  
  43. [ ! -z $NTPSVR1 ] &&  /sbin/setcfg NTP "Server1 IP" $NTPSVR1
  44. [ ! -z $NTPSVR2 ] &&  /sbin/setcfg NTP "Server2 IP" $NTPSVR2
  45. [ ! -z $NTPSVR3 ] &&  /sbin/setcfg NTP "Server3 IP" $NTPSVR3
  46.                
  47. #
  48. #Fix paths to "ntpdate" and "ntpd" (if necessary)
  49. [ -h "/usr/sbin/ntpdate" ] || ln -sf /sbin/ntpdate /usr/sbin/ntpdate
  50. [ -h "/usr/sbin/ntpd " ]   || ln -sf /sbin/ntpd /usr/sbin/ntpd
  51. #
  52. # Restart ntpd now that "ntpdate" and "ntpd" are in place
  53. #
  54. /etc/init.d/ntpd.sh restart        
  55. #
  56. #EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement