dantpro icon

QNAP NAS as NTP Server

dantpro | PRO | 04/03/14 02:38:10 AM UTC | 0 ⭐ | 9962 👁️ | Never ⏰ | []
AutoIt |

2.13 KB

|

None

|

0 👍

/

0 👎

#!/bin/sh
#
# http://forum.qnap.com/viewtopic.php?p=279111
# http://forum.qnap.com/viewtopic.php?f=85&t=5417&p=36422
# http://forum.qnap.com/viewtopic.php?f=24&t=55181&start=15#p279347
 
# Fix paths to "ntpdate" and "ntpd" (if necessary) and setup NTPd Daemon.  
# (based on suggestion by schumaku in:
#    http://forum.qnap.com/viewtopic.php?f=24&t=55181&start=15#p279223 )
#
# Written by Patrick Wilson 
# 
# Prerequisites: None 
#
# Purpose:
# 
# This script will use the upstream NTP Server (as set in the Admin WebUI),  and 
# determine the IP's addresses of the defined server.  It will then define these same
# IP addresses as the upstream servers for the local NTPD server on the NAS.  
#
# These IP addresses are pulled from "nslookup" instead of using hardcoded IP addresses, 
# in order to prevent accidental DoS attacks against the defined NTP server address.  
# 
# Extreme care has been taken in this script to ensure that only Busybox executables are used
# and each function is called with explicit fully qualified filenames to ensure no poor interactions 
# with any Optware packages that may be present. 
#
NTPSVR=`/sbin/getcfg NTP "NTP Server IP"`
NTPSVR_IPS=`/usr/bin/nslookup $NTPSVR | /bin/sed 's/[^0-9. ]//g'| /usr/bin/tail -n 1| /bin/awk -F " " '{print $1" "$2" "$3}'`
 
NTPSVR1=`echo $NTPSVR_IPS | /bin/cut -d " " -f 1`
NTPSVR2=`echo $NTPSVR_IPS | /bin/cut -d " " -f 2`
NTPSVR3=`echo $NTPSVR_IPS | /bin/cut -d " " -f 3`
 
echo The Upstream NTP Server - IP Addresses for this system are: $NTPSVR1 $NTPSVR2 $NTPSVR3
 
#
# Enable NTPD 
#
/sbin/setcfg NTP "Use NTP Server" TRUE
/sbin/setcfg NTP "Enable NTP Server" TRUE
 
[ ! -z $NTPSVR1 ] &&  /sbin/setcfg NTP "Server1 IP" $NTPSVR1
[ ! -z $NTPSVR2 ] &&  /sbin/setcfg NTP "Server2 IP" $NTPSVR2
[ ! -z $NTPSVR3 ] &&  /sbin/setcfg NTP "Server3 IP" $NTPSVR3
                
#
#Fix paths to "ntpdate" and "ntpd" (if necessary)
[ -h "/usr/sbin/ntpdate" ] || ln -sf /sbin/ntpdate /usr/sbin/ntpdate
[ -h "/usr/sbin/ntpd " ]   || ln -sf /sbin/ntpd /usr/sbin/ntpd
#
# Restart ntpd now that "ntpdate" and "ntpd" are in place
#
/etc/init.d/ntpd.sh restart        
#
#EOF

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎