#!/bin/sh # # # SETUP_NTP # Sample script to Configure and start NTPD (Network Time PRotocol) # in client mode on this host. # This will need modification on a per-site basis. # # *** DO NOT USE IT UNMODIFIED *** # # Tested against; # Solaris 2.5, 2.5.1, 2.6, 2.7, 2.8 # SunOS 4.1.4 # HP-UX 10.20 # IRIX 6.2, 6.4 # Linux Redhat 8.0 # # A.Gray 11 may 99 URL http://argray.org/ # # 11/10/03. Added condition for Linux. Tested on Redhat 8, likely to need modification for other variants # # echo "This script is provided as an example for setting up" echo "an NTP client on a number of Unix variants" echo "" echo "It WILL need modification on a per site basis." echo "" echo "NO WARRANTY OR STATEMENT OF FITNESS OF PURPOSE IS GIVEN." echo "YOU USE IT AT YOUR OWN RISK". echo "" echo "Do you understand this ?" echo "Enter 'yes' to continue, anything else will exit"; read a if [ x"$a" != x"yes" ]; then exit 1 fi # IFS=" " mydir="/ap/adm/ntp" ntpconf="$mydir/ntp_conf_client" # myname=`uname -n` for h in `awk '/^server/ {printf("%s ",$2)}' $ntpconf` do # echo "h = $h" if [ "$h" = "$myname" ]; then ntpconf="" echo "This machine is an NTP server - please configure /etc/ntp.conf manually" fi done # set -- `uname -sr` osname=$1 IFS="." export IFS set -- $2 majorrev=$1 minorrev=$2 IFS=" " export IFS if [ $osname = "SunOS" ]; then if [ $majorrev -gt 4 ]; then # Solaris if [ $minorrev -gt 5 ]; then # NTP shipped for 5.6 onwards echo "Solaris version 2.6 or above - using built-in NTP" if [ ! -z "$ntpconf" ]; then cp $ntpconf /etc/inet/ntp.conf fi sh /etc/init.d/xntpd start else # Use shareware for OS revs upto 2.5.1 echo "Solaris version 2.5.1 or below - using NTP 4.0.92h" if [ ! -z "$ntpconf" ]; then cp $ntpconf /etc/ntp.conf fi mkdir -p /usr/ntp/bin cp $mydir/solaris2.5.1/bin/* /usr/ntp/bin cp $mydir/solaris2.5.1/start_ntp /etc/init.d/ntp rm -f /etc/rc3.d/S20ntp ln /etc/init.d/ntp /etc/rc3.d/S20ntp sh /etc/rc3.d/S20ntp start fi else echo "SunOS 4.x - using NTP 4.0.92h" if [ ! -z "$ntpconf" ]; then cp $ntpconf /etc/ntp.conf fi mkdir -p /usr/ntp/bin cp $mydir/sunos4/* /usr/ntp/bin if [ `grep -c ntpd /etc/rc.local` -eq 0 ]; then # # Add entry for NTP to rc.local cat - << ENDRC >> /etc/rc.local if [ -x /usr/ntp/bin/ntpd ]; then echo "NTPD" /usr/ntp/bin/ntpd fi ENDRC fi /usr/ntp/bin/ntpd fi elif [ $osname = "HP-UX" ]; then echo "HP-UX - using builtin NTP" echo " ( you can safely ignore the message 'no server suitable..' )" if [ ! -z "$ntpconf" ]; then cp $ntpconf /etc/ntp.conf if [ -r /etc/rc.config.d/netdaemons ]; then ed /etc/rc.config.d/netdaemons << ENDED > /dev/null /XNTPD= s/=0/=1/ w q ENDED fi if [ -x /sbin/init.d/xntpd ]; then /sbin/init.d/xntpd start fi fi elif [ $osname = "IRIX" -o $osname = "IRIX64" ]; then # # Install/update ntp if [ $majorrev -gt 5 ]; then echo "IRIX 6.x" inst -f /ap/adm/ntp/irix6.2 -a -M -u all else echo "IRIX 6.x" inst -f /ap/adm/ntp/irix5.3 -a -M -u all fi # # Disable timed and enable ntp at boot time /sbin/chkconfig timed off /sbin/chkconfig ntp on # # If timed is running kill it. pid=`ps -ef | grep timed | grep -v grep | awk '{print $2}'` if [ ! -z "$pid" ]; then kill $pid fi # # Install NTP.conf if [ ! -z "$ntpconf" ]; then cp $ntpconf /etc/ntp.conf fi # # Wollop timetrim - NTPD will sort this out later rm -f /etc/config/ntp.timetrim # # Ensure ntp is started at boottime rm -f /etc/rc2.d/S21ntp ln -s /etc/init.d/ntp /etc/rc2.d/S21ntp cat << ENDOPT > /etc/config/ntp.options -f /usr/freeware/etc/ntp.drift -c /etc/ntp.conf ENDOPT # # start NTP now. sh /etc/rc2.d/S21ntp start elif [ $osname = "Linux" ]; then echo "Linux..." if [ ! -z "$ntpconf" ]; then cp $ntpconf /etc/ntp.conf fi sh /etc/init/ntpd start fi