Quantcast
Channel: PirateBox Forum - Raspberry Pi(rate)Box
Viewing all articles
Browse latest Browse all 1863

Re: Timesave with date v.8.23

$
0
0
Hey Matthias,

I run the very first ArchLinux Image we had...
Thanks for the timesave.service, I hope it does its job ;-)

I got the timesave script working for me now, changing the format to the "default" kina worked, but introduced a new problem: the timesave script compares the two dates and checks if we change the time backwards (which is clever) -> it can't do that correctly with a date that looks like "Sun Oct 12 22:20:34 MDT 2014" because... how the hell should it know how to do that.

In the end, I removed all these checks. Manually calling the timesave script works (save and restore), so I guess it works automatically as well. Here is the current version running:

#!/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

Thanks for your help! I think it's working now :P

Viewing all articles
Browse latest Browse all 1863

Trending Articles