I wrote a little script that does the time work.
This I hope works for all rPi users who want to have kind of accurate times, at least not wildly innacurate ones, and need to deal without an internet connection at times.
For having this run regularly, I have it run as a cron job every minute, so if I wait a minute after bootup, it'll update. Much easier if my Raspberry Pi crashes than using a service.
It also doesn't fight with network time, so if your network time is working (or will), this script won't care.
#!/bin/bash
# Version 1.0.
# By Aviator 45003, Aviator45003 [at] gmail.com
# This program is distributed under the GPL-3.0 Public License.
# However, it would be nice if you, being a programmer, if you make changes,
# would send them to the original programmer so
# he could improve his style.
# Program must be run as root if the user wouldn't have permissions to
# edit the PATH_TO_TIME_FILE
PATH_TO_TIME_FILE="/etc/time_rPi_last";
THRESHHOLD=1971;
# Any changes past this point should be submitted to [email protected]
touch $PATH_TO_TIME_FILE;
CUR_DATE=$(date +"%Y");
# Check that we have a date to fall back on.
if ( (($CUR_DATE < $THRESHHOLD)) && [ -e $PATH_TO_TIME_FILE ] ) ; then
NEW_DATE_STRING=$(cat $PATH_TO_TIME_FILE);
date -u $NEW_DATE_STRING;
# If we don't have a fallback date, and we need one, just ask!
# If this is being called regularly, there is a problem.
elif (( $CUR_DATE < $THRESHHOLD )); then
echo "Enter a new date: Month Day Hour Minute Year: MMDDhhmmYYYY";
read NEW_DATE_STRING;
date -u $NEW_DATE_STRING;
fi
# Write the fallback date. Also updates the file every time this script is run.
if (( $CUR_DATE > $THRESHHOLD)); then
echo $(date +"%m%d%H%M%Y") > $PATH_TO_TIME_FILE;
fi
exit 0;