Timesave with date v.8.23 October 12, 2014 03:01PM |
Registered: 10 years ago Posts: 37 |
blabla... */5 * * * * /opt/piratebox/bin/timesave.sh /opt/piratebox/conf/piratebox.conf save
date: invalid date '201410121620'
date +%Y%m%d%H%M -s "201410121620" gives me "date: invalid date '2014.....'" date +%C%g%m%d%H%M -s "201410121620" gives me "date: invalid date '2014.....'" (version used in the timesave.sh script)
date +%Y%m%d -s 20141012 date +%T -s 16:58:00
Re: Timesave with date v.8.23 October 12, 2014 06:06PM |
Admin Registered: 13 years ago Posts: 4,680 |
[Unit] Description=Restore fake RTC-time [Service] ExecStart=/bin/bash /opt/piratebox/bin/timesave.sh /opt/piratebox/conf/piratebox.conf recover [Install] WantedBy=multi-user.target
systemctl enable timesave.service
sed 's|date `c|date -s `c|' -i /opt/piratebox/bin/timesave.sh sed 's|date +%C%g%m%d%H%M|date|' -i /opt/piratebox/bin/timesave.sh(I added those fixes to the package-prepare of a REAL archlinux package file, so the file is fixed for the archlinux version)
Re: Timesave with date v.8.23 October 12, 2014 08:26PM |
Registered: 10 years ago Posts: 37 |
#!/bin/sh # This script enables a sort of timerescue System # for Systems without a Realtime Clock # like TP-Link MR3020 , RaspberryPI # # It does not reflect the real time, but # gives a sort of stability to complete standalone # systems. # # Licenced under GPL-2 @ 2012 # Matthias Strubel matthias.strubel@aod-rgp.de ##function for similar saving & getting time get_datetime() { date } # Load configfile if [ -z $1 ] || [ -z $2 ] ; then echo "Set up a crontab entry for regulary saving the time" echo "Usage $0 <path to piratebox.conf> <step>" echo " Valid steps are:" echo " install - installs the needed parts into crontab" echo " save - saves time into file" echo " recover - recovers the time from a file" exit 1 fi . $1 if [ "$2" = "install" ] ; then crontab -l > $PIRATEBOX_FOLDER/tmp/crontab 2> /dev/null echo "#--- Crontab for PirateBox-Timesave" >> $PIRATEBOX_FOLDER/tmp/crontab echo " */5 * * * * $PIRATEBOX_FOLDER/bin/timesave.sh $PIRATEBOX_FOLDER/conf/piratebox.conf save " >> $PIRATEBOX_FOLDER/tmp/crontab crontab $PIRATEBOX_FOLDER/tmp/crontab echo "initialize timesave file" touch $TIMESAVE chmod a+rw $TIMESAVE get_datetime > $TIMESAVE echo "Remember MAY have to cron active..." echo " on OpenWrt run: /etc/init.d/piratebox enable" exit 0 fi if [ "$2" = "save" ] ; then # if [ -e $TIMESAVE ] ; then # if [ `get_datetime` -lt `cat $TIMESAVE` ] ; then # logger -s "$0 : sorry, current date-time is lower then saved one, don't save it this time" # exit 1 # fi # fi #Save Datetime in a recoverable format... get_datetime > $TIMESAVE exit 0 fi if [ "$2" = "recover" ] ; then # if [ `get_datetime` -lt `cat $TIMESAVE` ] ; #then date -s "`cat $TIMESAVE `" [ "$?" != "0" ] && echo "error in recovering time" && exit 255 echo "Time recovered" exit 0 # else # echo "Sorry, changing timebackward via timesave is not possible" # exit 1 # fi fi
Re: Timesave with date v.8.23 October 12, 2014 08:28PM |
Admin Registered: 13 years ago Posts: 4,680 |
Re: Timesave with date v.8.23 October 12, 2014 08:31PM |
Registered: 10 years ago Posts: 37 |
Re: Timesave with date v.8.23 October 12, 2014 08:36PM |
Admin Registered: 13 years ago Posts: 4,680 |