I was searching for some auto-update script to update the board with server date (I'm not using battery for RTC), then after lot of work(I'm newbie at Linux), this worked for me (that I think is the "best way to set timezone / date").
I tried create my own file at /etc/init.d/ and update boot list with update-rc.d. But its not a easy job for newbies, so I edited the last file loaded after all system boot (/etc/init.d/galileod.sh):
start_galileod()
{
#PIOL startup script before arduino load:
#/home/root/piol.init
echo "Starting galileod"
start-stop-daemon -q -S -m -p $pidfile -b -x $launcher
start-stop-daemon -q -S -m -p $pidsreset -b -x $sreset -- -i $input_reset_gpio -o $output_reset_gpio
#PIOL startup script after arduino load:
/home/root/piol.init
}
As you can see, you can put your script before or after the sketch of Arduino load.
Then, here is part of my piol.init.
# Try Update date from server every 10s (until network access ok)
while [ 1 ]; do
a=$(rdate -s time.nist.gov 2>&1)
if ! `echo ${a} | grep "bad address" 2>&1 >/dev/null`;
then
/bin/bash /etc/init.d/hwclock.sh "reload"; exit;
fi
sleep 10
done
Based on this script (matthias-hahm): "This script will try every 10 second to ntp sync date with in my case time.nist.gov (put in whatever ntp server you prefer) until network is accessible (and hence "bad address" will not be printed) and will exit then." Plus, before exit, it will set the hardware clock too with the date.
Now, after all reboot, system time will be always updated with server.
If you want change the default timezone of system, edit line 9 of /etc/profile with your timezone: TZ="UTC+03:00" (Brazil ).
Regards,
R. Piol.