Automatically syncing with time-server


GuSec

Member
Joined
Dec 29, 2008
Messages
153
Age
33
Location
Northern Sweden
To my surprise, ntpdate/ntpd isn't avaible, but I found /usr/bin/rdate instead. So I've installed cron and root's crontab now looks like this for me:



Code:
# SYNC (SYS)TIME WITH SERVER AND SYNC (SYS)TIME WITH HARDWARE CLOCK

*/15 * * * * /usr/bin/rdate -ns 0.se.pool.ntp.org >/dev/null 2>&1 && hwclock -w >/dev/null 2>&1

(0.se is because my Pandora is a Swedish resident)


Is there some serious downside to this? Can (and should) I do it in a smarter way? The best would of course be to only have it sync when there's an actual wifi-connection, but I couldn't figure out a smart way to achieve this (my Pandora is connected pretty much all the time).


Anyone doing anything similar? Input?
 
Use the /etc/NetworkManager/dispatcher.d/* scripts.


Create a ntp.sh script, make it executable, and cook it like this:



Code:
#!/bin/sh

case "$2" in

up)

   if [ "$1" == "wlan0" ]; then

/usr/bin/rdate -ns 0.se.pool.ntp.org >/dev/null 2>&1 && hwclock -w >/dev/null 2>&1

   fi

   if [ "$1" == "wlan1" ]; then

/usr/bin/rdate -ns 0.se.pool.ntp.org >/dev/null 2>&1 && hwclock -w >/dev/null 2>&1

   fi

   if [ "$1" == "wlan2" ]; then

/usr/bin/rdate -ns 0.se.pool.ntp.org >/dev/null 2>&1 && hwclock -w >/dev/null 2>&1

   fi

   if [ "$1" == "wlan3" ]; then

/usr/bin/rdate -ns 0.se.pool.ntp.org >/dev/null 2>&1 && hwclock -w >/dev/null 2>&1

   fi

;;

down)

   # anything related here

;;

*)

   # anything related here

;;

esac
 
this is a very handy script thanks :)


edit


question is cron installed from angstrom?


edit2


also is cron required for the script linux-swat provided?
 
Last edited by a moderator:
Crontab should be available by default u can load up your crontab by typing crontab -e i dont know to do roots crontab though maybe just type su in terminal to switch to root user then type crontab -e and paste the code in there, the ntp.sh script can be run from the terminal without cron, cron just runs it automatically for you at certain times.
 
Crontab should be available by default u can load up your crontab by typing crontab -e i dont know to do roots crontab though maybe just type su in terminal to switch to root user then type crontab -e and paste the code in there, the ntp.sh script can be run from the terminal without cron, cron just runs it automatically for you at certain times.
crontab is giving me no command found?
 
crontab is giving me no command found?
It should be available from start, but it is NOT!


Do this:



Code:
sudo opkg update

sudo opkg install cron


And it should be installed and fully working!


EDIT: Linux-SWAP, great script! It works perfectly! Amazing work.
 
Last edited by a moderator:
crontab is giving me no command found?
It should be available from start, but it is NOT!


Do this:



Code:
sudo opkg update

sudo opkg install cron


And it should be installed and fully working!


EDIT: Linux-SWAP, great script! It works perfectly! Amazing work.

unfortunately i get message - cannot install package cron?
 
fyi the script by linux-swat works without cron. imo should be provided in next release as it is very useful since with the battery meter issues one has to take battery out and so having this automatic time sync script is highly useful.


cheers
 
A wifi/ethernet USB stick I assume?
I assume so too. Scripts in that folder get executed after a connection has been established, except the rather rare case that the network interface one is using gets another name than wlan0,1,2,3 (like using a USB2Ethernet adapter) the script should work out of the box
 
I followed the instructions regarding making the ntp.sh. When trying to run it in the Terminal, it gives me an error regarding something missing in line 2.
 
Back
Top