March 25, 2010, 09:17:49 pm
News:
Pages: [1]
Print
Author Topic: Timesync on boot?  (Read 1841 times)
pfft2001
Full Member
***
Posts: 130


View Profile
« on: July 14, 2009, 06:28:31 am »

What is the easiest way to add a script (program) to run at boot time?

Notes:
1) I am familiar with the general Linux routine - adding something to the RC files - but haven't done it on the OSD (yet).
2) As indicated in the Subject: line, I want to run my timesync program to fix the clock - sometime shortly after booting.
Logged
ChadV
Administrator
Hero Member
*****
Posts: 1229


View Profile WWW
« Reply #1 on: July 14, 2009, 07:46:43 am »

https://help.ubuntu.com/community/UbuntuTime

Something like this?
Logged
pfft2001
Full Member
***
Posts: 130


View Profile
« Reply #2 on: July 14, 2009, 08:18:32 pm »


The question isn't so much "I need a program/utility/application/whatever to do time sync".

I've got that - I wrote it myself and it works fine.

What I need is to know is how to hook it into the OSD's boot sequence.    My understanding is that there is a small amount of writable disk space on the device and that you can edit the RC files.  But I don't know the details.  That's what I need help with.
Logged
ChadV
Administrator
Hero Member
*****
Posts: 1229


View Profile WWW
« Reply #3 on: July 15, 2009, 07:54:16 am »

Agh!  Sorry, I wasn't paying attention and thought this was over in the LINK section.  >.>

Yeah, you can add things to the rc files.

/mnt/OSD/rc.user is processed on boot, make sure its permissions are 755.
Logged
pfft2001
Full Member
***
Posts: 130


View Profile
« Reply #4 on: July 19, 2009, 09:44:31 am »

OK, that sounds reasonable/do-able.

One more thing, related to this: Is there any way to make the time setting persist across reboots (so the immediate time sync wouldn't be necessary) ?

I think (but am not sure) that when I first got the unit, I set the time through the GUI, but since then have done it via scripts (i.e., the Unix "date" command).  And, I think, thus, that whenever it boots up, it has the time from the time set via the GUI. I.e., I am theorizing that setting it via the GUI someone saves it in a location that persists across boots.  Is that right?  (And, if so, is there a way to do this via script?)
Logged
ChadV
Administrator
Hero Member
*****
Posts: 1229


View Profile WWW
« Reply #5 on: July 19, 2009, 10:21:06 pm »

O.o

I'm not sure what you're asking...  Either you're trying to do something complex that I'm not grasping, or you have no understanding on how a computer clock operates.

When you set the clock (whether through the GUI, a command utility, a cron job, a startup script, or whatever), it sets the system clock, which synchronizes the hardware clock to match.  In most hardware (the OSD included), the hardware clock persists when power is cut, and is how the operating system knows what time it is on boot.

The only reason for running a time sync tool like NTPDate is to make sure the drift of the hardware clock (the inherent inaccuracy, normally about a second per month or so) is synced to a more authoritative source like NIST.
Logged
pfft2001
Full Member
***
Posts: 130


View Profile
« Reply #6 on: July 20, 2009, 08:00:04 pm »


I'm not sure what you're asking...  Either you're trying to do something complex that I'm not grasping, or you have no understanding on how a computer clock operates.


I can assure you that neither assumption is true, so I must not have explained myself clearly.

Here it is, step by step:
1) When I boot my OSD, the time is behind by about 55 minutes.  This is very constant across many repetitions.  Note that this is just less than an hour.  Normally, when things are off by an hour, it is usually a DST issue; that is a possibility here.  (If they are off by an integer number of hours greater than 1, it is usally a time zone issue)

2) I telnet in and set the date/time via the Unix "date" command.  I watch the on screen display and within a few minutes, the on screen display (which I usually refer to as "the GUI" - note that most other consume products in the same general genre as the OSD refer to this as "the on-screen display" or the OSD; obviously, that term is already taken here...) refreshes itself to the new time.  Note that this refresh doesn't happen immediately, but that's OK.

3) Now, the thing is, I think that when I first got the unit, it in the winter, and I set it via the menus (i.e., via "the GUI").  Since then (i.e., after DST started) I have always set it via the Unix "date" command.  So, you see where I am going with this - I'm guessing that on reboot, it is picking up the time from when it was running in "standard time".  Now, having written all this, I could have tested it myself (setting the time via the GUI), but I actually don't have the time/inclination to do that - I've got a lot of things going on and not that much time to devote to hacking the OSD.

4) Note that I don't know that much about Linux on ARM, but I know a lot about Linux on x86, and, as you know, one of the "features" of x86 hardware is that it maintains 2 different "time"s - the system time and the hardware clock time, and it usually takes some explicit command to sync them.  In DOS versions prior to 3.3, you had to manually sync them; as of DOS 3.3, it is done automatically.  In Linux (on x86). there is the "hwclock" command that you must use to keep them in sync.  I checked and found that the OSD does not have the "hwclock" command; I assume that means it is not necessary.  But, the point is, if you are running Linux on x86 and set the system time, but don't set the hardware clock via hwclock, then the time setting is lost on the next boot (it reverts to whatever it was before).


Does that clear things up?
Logged
ChadV
Administrator
Hero Member
*****
Posts: 1229


View Profile WWW
« Reply #7 on: July 21, 2009, 11:55:45 am »

Ah, okay.  Now I'm seeing what you're saying.

It sounds like the GUI is running the HW synchronization, but the command line is not.

Hopefully someone with better knowledge of the underpinnings can help out.
Logged
tn
Jr. Member
**
Posts: 51


View Profile
« Reply #8 on: July 21, 2009, 07:18:31 pm »

Hi!
For Torfu, setting RTC (hardware clock)...
  http://forums.neurostechnology.com/index.php?topic=8377.0
(Sorry. I am not using Arizona)

My OSD unit works very well and it is very stable (now about 1year+10months! (24/7)!)  Thanks.
« Last Edit: July 21, 2009, 07:20:15 pm by tn » Logged
yanvrno
Full Member
***
Posts: 110


View Profile
« Reply #9 on: July 23, 2009, 12:30:36 pm »

either of these two command at the prompt gets and sets the correct time but it will be off by the timezone and DST your in.

rdate -s time-a.nist.gov
or
rdate -s time-a.timefreq.bldrdoc.gov

if someone could figure out a way to add 5 hours to it in the script that would be great.
But it is accurate.
a settime.sh script could be run in the user.rc script at bootup

chmod 755 settime.sh    (Change the mode, So it is executable)
my script is in the '/' Root directory as of now.
and I do it manually now because i dont have a big clock issue, stays in time real well.
   
cd /
.  ./settime.sh

or just type in the rdate line at the prompt.

After I run my script I have to go to the Tools/Settings/Date & Time menu to subtract the 5 hours.
Then I know its within a couple of seconds at least to the world.

Anyone care to show me a better way.    I Thank Eee!
« Last Edit: July 26, 2009, 04:26:52 am by yanvrno » Logged
greyback
Administrator
Hero Member
*****
Posts: 1483


View Profile
« Reply #10 on: July 23, 2009, 01:36:14 pm »

yanvrno: Did you try setting the TZ variable with your timezone info?

You could try running
Code:
export TZ=EST-5[code]
before calling rdate and see what it does to the time.

EST stands for 'standard time' or Greenwich Mean Time, with no daylight savings. Then I stuck in the "-5" to subtract 5 from it. See here for the least-horrific guide I could find:
http://www.di-mgt.com.au/wclock/tz.html

Mind you, I think you should try "EST+5", but there's no guarantee this will work on the OSD either.
-G
[/code]
Logged
yanvrno
Full Member
***
Posts: 110


View Profile
« Reply #11 on: July 23, 2009, 04:40:28 pm »

I added this line to my script
export TZ=EST+5
though it looks like it works
the GUI display  and the date command do not sync
off by 5 hours
Never updates the GUI date
I can get the date command correct but the GUI is not

Had better luck before Now i'm just scratching my head.

went back to this to straighten out everything
export TZ=EST+0EDT+0,M3.2.0/2,M11.1.0
I have to assume that the scheduler runs off the internal date not the GUI time
Or i will have to manually update the display thru the menu.
Has been a good lesson in creating a script. Thanks

update July 28 2009 I now have a script that might work, time will tell (see code below)
the case statement is used to make sure the time is in the two digit format.
update Aug 8 added a status catch to make sure internet world time clock is connected

this script runs in the background and updates every24 hours
this sets the clock correctly and also the GUI display is now right

run this at the command prompt or I am told it could go in the /mnt/OSD/rc.user file and run at boot time
. ./settime.sh --quiet >/dev/null 2>&1 &

#the settime.sh script
Code:
#!/bin/bash
 # time and date are formatted to show HH:MM:SS YYYY-MM-DD
echo "Presently set to"
 date +"%H:%M:%S %F"
echo "Just another way to format it"
 date

export TZ=EST+0EDT+0,M3.2.0/2,M11.1.0

hour=24;min=60;sec=60
let day=$hour*$min*$sec
i=1
while [ $i -le 30 ] #should run 30 days
do
   if [ $i = "30" ]; then
     break
   else
     let i=$i+1
   fi
   rdate -s time-a.timefreq.bldrdoc.gov
let status=$?
if [ $status = "0" ]; then
        echo connected to the "World Time clock"
        date

        Year=`date '+%Y'`
        month=`date '+%m'`
        day=`date '+%d'`
        hour=`date '+%H'`
        Min=`date '+%M'`
        Sec=`date '+%S'`
        C=`date '+%C'`
        Z=`date '+%z'`

        zero="0"
        h=`expr $hour - 4`
        
        case "$h" in
        [1] | [2] | [3] | [4] | [5] | [6] | [7] | [8] | [9])
        hour=$zero$h
        #echo "Need to add zero",       $hour
          ;;
        *)
          hour=$h
          #echo "Time is Formated Correct",$hour
          ;;
        esac

        echo "Now the OSD has been updated"
         date -s $month$day$hour$Min.$Sec$Year
        sleep $day;
fi
done
« Last Edit: August 08, 2009, 12:37:17 pm by yanvrno » Logged
Pages: [1]
Print
Jump to: