[maemo-users] Handy script for using ntpdate

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Here's a little script I knocked up to allow easy syncing of the Nokia's 
time to an NTP server.

It has the following prerequisites:

1) ntpdate must be installed.
2) the /usr/bin/ntpdate executable must be marked as SUID root.
3) /etc/sudoers must have the following line added:
user ALL = NOPASSWD: /mnt/initfs/usr/bin/retutime *

Given that, then this script will:

a) identify the current default gateway
b) Attempt to sync to an NTP server there (many gateways will be running 
NTPD so their log files can be correctly timestamped).
c) If that is successful, commit the new time to the RTC using the 
retutime command.
d) If that is NOT successful, then attempt to use one of the 
pool.ntp.org servers to sync.
e) if that is successful, then commit the time.

I've placed this command into /home/user/bin, and created an entry in 
the loadapplet command list for it - thus, I can connect, force a sync, 
and have the clock be set correctly.

Bonus points if somebody wanted to either a) hook this into the network 
connect scripts or b) hook in the "force network connection active" 
command into this.

#!/bin/sh
# if no args give, re-run with the default route
if [ -z $1 ]
then
    exec $0 `/sbin/route | grep ^default`
fi

# extract the default route destination
gateway=$2

# OK, see if he is running a time server, and use him if so
echo Trying to sync to $gateway
if /usr/sbin/ntpdate -t .5 -u -b -p8 $gateway
then
    echo synced to $gateway
    sudo /mnt/initfs/usr/bin/retutime -I
    exit 0
fi
# if that didn't work, try for a pool server
echo Trying to sync to pool.ntp.org
if /usr/sbin/ntpdate -u -b -p8 pool.ntp.org
then
    echo synced to pool.ntp.org
    sudo /mnt/initfs/usr/bin/retutime -I
    exit 0
fi
exit 1




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Big List of Linux Books]    

  Powered by Linux