[maemo-users] [maemo-users] Handy script for using ntpdate
From: David D. Hagood wowbagger at sktc.netDate: Sun Aug 13 18:59:14 EEST 2006
- Previous message: [maemo-users] Problems with audio-playback since IT2006 update
- Next message: [maemo-users] No connection when no traffic
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: [maemo-users] Problems with audio-playback since IT2006 update
- Next message: [maemo-users] No connection when no traffic
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
