1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Set time when NTP server not viable

Discussion in 'Tomato Firmware' started by reddwarf, Feb 7, 2012.

  1. reddwarf

    reddwarf Networkin' Nut Member

    Hi Everyone

    I have an n12 with Tomato Firmware v1.28.7495 MIPSR2-Toastman-RT K26 VPN and it is working great exept for one issue. The location does not have access to NTP (only port 80 and 443 are allowed through the firewall). I have to set the time manually (ssh into box and issue date MMDDhhmmYYYY. But this does not persist and I have to do it everytime the router is plugged in (Daily). Is there a hardware clock that I can set? Or a script that can pull the time from http?
     
  2. jsmiddleton4

    jsmiddleton4 Network Guru Member

    I'd like to see the same thing. Maybe a script that can run on boot up? I still can't get my slave that is configured in wireless ethernet bridge mode to get the time.
     
  3. ntest7

    ntest7 Network Guru Member

    These little routers don't have a hardware time clock; the only way they can get the time automatically is via an NTP server.
    Maybe you can set up a PC inside the network as an NTP server, and configure the router to get the time from there. Or maybe your firewall device can supply NTP time.

    This seems to work for WinXP or Win7
    http://support.microsoft.com/kb/314054
     
  4. Monk E. Boy

    Monk E. Boy Network Guru Member

    If you have a Windows domain, you can (usually) pull NTP time from a domain controller.
     
  5. jsmiddleton4

    jsmiddleton4 Network Guru Member

    Question is how to get the router to go an look and set the time.....
     
  6. mstombs

    mstombs Network Guru Member

    Set the "ntp_server" nvram var?
     
  7. Planiwa

    Planiwa LI Guru Member

    So, here's how:

    Code:
    wget http://tycho.usno.navy.mil/cgi-bin/timer.pl -O - 2>&1| grep EST | sed -e 's/<BR>//' -e 's/Ea.*//'
    
    The rest is left as an exercise for the reader. :)
     
  8. jsmiddleton4

    jsmiddleton4 Network Guru Member

    Thanks for helping. Put that line in the init script section. Rebooted. Did not set time for the router.

    Also it appeared to keep checking the time, cpu use at 100%, although it never wrote the time back to the date/time variable in the firmware.
     
  9. jsmiddleton4

    jsmiddleton4 Network Guru Member

    I'm not a script writer linux guy. So I appreciate the help. I have no idea how to write the thing but wouldn't it look like this?

    Set user_time_zone.
    Go get user_time_date.
    Store user_time_date.
    Stop get user_time_date.
    Write user_time_date to date variable.
    Exit

    What would it take to add a manually triggered time/date feature in the gui?
     
  10. jsmiddleton4

    jsmiddleton4 Network Guru Member

    Pl...

    Got it to report time in "Notes" section in "System Commands" tab. Able to set to my time zone by changing EST to MST.

    wget http://tycho.usno.navy.mil/cgi-bin/timer.pl -O - 2>&1| grep MST | sed -e 's/<BR>//' -e 's/Ea.*//
     
  11. Planiwa

    Planiwa LI Guru Member

    Code:
    $(wget http://tsmr.org/date.php -O - 2>&1 |grep date)
    Put this in WAN-Up script.
     
  12. jsmiddleton4

    jsmiddleton4 Network Guru Member

    Doing that now. How will it now my time zone?

    Rebooting.....

    Does not work in WANUP. Does work in system execute area. Sets time. Sets it to looks like EST.

    Thinking it won't work in WANUP. This router is a slave in wireless ethernet bridge mode.
     
  13. Planiwa

    Planiwa LI Guru Member

    It needs to be able to access the Internet. You will have to figure out when it can do that. Perhaps you can schedule it for 1970-01-01 00:15 or something like that.

    As for time zone, perhaps UTC is the answer?:

    Code:
    $(wget http://tsmr.org/date.php -O - 2>&1 | sed -n '/UTC/s/UTC//p')
    
     
  14. jsmiddleton4

    jsmiddleton4 Network Guru Member

    "It needs to be able to access the Internet"

    It can. Ping from it just fine.

    WAN is converted to a LAN port. Connection between 2 routers is wireless on 5ghz channel.

    Seems to me something isn't quite right in firmware when set to wireless ethernet bridge mode regarding the time set function. It is such a small matter I can't imagine its on anyone's radar to address. However the dots don't seem to connect properly to set the time.

    That is why I'm looking for a script to do so. My situation different than the post regarding limited port availability and needing to reset time/date each time router is turned on.

    I need to tell the script UTC-7 somewhere.
     
  15. reddwarf

    reddwarf Networkin' Nut Member

    Hi Guys I get this working by creating a webpage on a webserver (my own :)) with this code:
    PHP:
    <?php
    print gmstrftime('%m%d%H%M%Y');
    ?>
    This will get you a return with the properly formatted date time from an external webserver. Then in tomoato put this in the Administration - Scripts - WAN UP page:
    Code:
    #!/bin/sh
    /bin/sleep 5
    /bin/cat <<END > /tmp/setdate.sh
    #!/bin/sh
    logger DATE_TIME Script Executing
    eval SOURCE="http://www.your web server.com/dir/file.php"
    wget \$SOURCE -O - > /tmp/TIMEFILE
    chmod 755 /tmp/TIMEFILE
    TEMPTIME=\`cat /tmp/TIMEFILE\`
    date -u \$TEMPTIME
    logger DATE_TIME Script completed: \$TEMPTIME
    END
    /bin/chmod 755 /tmp/setdate.sh
    /usr/sbin/cru a SetDateFromISPCGIPerl "0 * * * * /tmp/setdate.sh >/dev/null 2>&1"
    while [ `/bin/date | /usr/bin/cut -d " " -f 7` = "1969" ]
    do
      /bin/sleep 5
      /tmp/setdate.sh
    done
    That should do it. I have a web proxy in the way too, so next effort is to figure out how to have the router pass NTLM auth to a webserver address.... I just connect with a client and wait for the script to rerun.
     
  16. jsmiddleton4

    jsmiddleton4 Network Guru Member

    Trying it now. My only concerns is as already shared I'm not sure the slave ever gets to WANUP..... Also would be nice to have it configured for a standard time server. Would not want to create a situation where your webserver being up or down becomes a problem.

    Booting now....

    Did not work in WANUP.

    When run in Tools..System get this error.

    [: 1969: unknown operand

    Or are you creating an inside you network only webserver to which you direct your router to get the time?
     
  17. Planiwa

    Planiwa LI Guru Member

    FWIW -- I have made the format more sensible.

    The web page now displays:

    2012-02-08 16:23
    201202081623.04 EST
    201202082123.04 UTC
    1328736184 Unix

    date -u -s $(wget http://tsmr.org/date.php -O - 2>&1 | sed -n '/UTC/s/UTC//p')

    might be satisfactory.
     
  18. jsmiddleton4

    jsmiddleton4 Network Guru Member

    Works and lets my setting in Time, UTC-7, to be applied so my time/date are correct. Only works when I run it from Tools System. Does not work in either Init or WANUP Scripts in Admin. Which is fine. I can run it from Tools when I need to. Will need to figure out a place to store if for after firmware update.
     
  19. jsmiddleton4

    jsmiddleton4 Network Guru Member

    So the fact that I can run that script, it actually reads the time/date, and sets it is telling me the router is getting out to the web. Yes?
     
  20. Planiwa

    Planiwa LI Guru Member

    There is no question that the Internet is accessible eventually. The question is: when does it become accessible? The usual answer is: WAN-Up. Perhaps the most sensible approach might be to schedule it every hour.
     
  21. jsmiddleton4

    jsmiddleton4 Network Guru Member

    Tired scheduling it, etc., and that doesn't work either. Really seems to be something missing in the firmware when set to ethernet bridge mode.

    Works as expected in WDS mode by the way.
     
  22. jsmiddleton4

    jsmiddleton4 Network Guru Member

    I'm not sure how to describe exactly or technically but I think it has to do with the way the master "sees" the slave, or doesn't see the slave, in ethernet bridge mode. You can see similar symptom if trying to do things like MAC filtering, ARP assigned IP's, etc for devices attached to the slave. Could be all that is needed is some simple port forwarding rule, etc., in the master...

    In other words the slave router can get out to and ping the internet just fine. The problem is the information coming back to the slave router from the time server can't find the slave router so the slave router never gets the time information.
     
  23. Planiwa

    Planiwa LI Guru Member

    I propose:

    Make a custom scheduled event which, every minute (yes!) does:

    logger "date -u -s $(wget http://tsmr.org/date.php -O - 2>&1 | sed -n '/UTC/s/UTC//p')"

    [SAVE]

    Then after a couple of minutes, look at the end of your message log and you will see something like:
    Code:
    Feb 8 19:09:01 ROUTER cron.info crond[25842]: crond: USER root pid 17485 cmd sched sch_c3
    Feb 8 19:09:01 ROUTER user.info sched[17486]: Performing scheduled custom #3...
    Feb 8 19:09:02 ROUTER user.notice root: date -u -s 201202090009.02
    
    Report back.
     
  24. jsmiddleton4

    jsmiddleton4 Network Guru Member

    Where am I putting this?

    Never mind, figured it out.
     
  25. jsmiddleton4

    jsmiddleton4 Network Guru Member

    Never seems to run.

    Dec 31 17:01:09 Front-Room user.info init[1]: Linksys E3000: Tomato 1.28.7495 MIPSR2-Toastman-RT K26 USB Ext
    Dec 31 17:01:17 Front-Room daemon.err nmbd[680]: Samba server FRONT-ROOM is now a domain master browser for workgroup HOME-SYSTEM on subnet 192.168.2.11
    Dec 31 17:01:32 Front-Room daemon.err nmbd[680]: Samba name server FRONT-ROOM is now a local master browser for workgroup HOME-SYSTEM on subnet 192.168.2.11
     
  26. jsmiddleton4

    jsmiddleton4 Network Guru Member

    However if I run the command line from the Tools System get this for last line in log.

    Dec 31 17:04:26 Front-Room user.notice root: date -u -s 201202090041.42
     
  27. Planiwa

    Planiwa LI Guru Member

    What does

    nvram find sch_

    return?
     
  28. jsmiddleton4

    jsmiddleton4 Network Guru Member

    sch_c1=0,-1,127
    sch_c1_cmd=logger "date -u -s $(wget http://tsmr.org/date.php -O - 2>&1 | sed -n '/UTC/s/UTC//p')"
    sch_c2=0,-30,127
    sch_c2_cmd=
    sch_c3=0,-30,127
    sch_c3_cmd=
    sch_c4=
    sch_c4_cmd=
    sch_c5=
    sch_c5_cmd=
    sch_rboot=0,0,127
    sch_rcon=0,0,127

    Correction:

    Made sure I saved it and it was enabled. Now says:
    sch_c1=1,-1,127
    sch_c1_cmd=logger "date -u -s $(wget http://tsmr.org/date.php -O - 2>&1 | sed -n '/UTC/s/UTC//p')"
    sch_c2=0,-30,127
    sch_c2_cmd=
    sch_c3=0,-30,127
    sch_c3_cmd=
    sch_c4=
    sch_c4_cmd=
    sch_c5=
    sch_c5_cmd=
    sch_rboot=0,0,127
    sch_rcon=0,0,127
     
  29. jsmiddleton4

    jsmiddleton4 Network Guru Member

    Still only have this in log...

    Dec 31 17:01:17 Front-Room daemon.err nmbd[658]: Samba server FRONT-ROOM is now a domain master browser for workgroup HOME-SYSTEM on subnet 192.168.2.11
    Dec 31 17:01:32 Front-Room daemon.err nmbd[658]: Samba name server FRONT-ROOM is now a local master browser for workgroup HOME-SYSTEM on subnet 192.168.2.11
     
  30. jsmiddleton4

    jsmiddleton4 Network Guru Member

    No additions to log. No indication of getting time/date unless I manually trigger the command line to do so via Tools System.
     
  31. jsmiddleton4

    jsmiddleton4 Network Guru Member

    Last 25 lines.

    Dec 31 17:00:49 Front-Room user.notice kernel: scsi 0:0:0:0: Direct-Access ST350062 0AS PQ: 0 ANSI: 2
    Dec 31 17:00:49 Front-Room user.notice kernel: sd 0:0:0:0: [sda] 976773168 512-byte hardware sectors (500108 MB)
    Dec 31 17:00:49 Front-Room user.notice kernel: sd 0:0:0:0: [sda] Write Protect is off
    Dec 31 17:00:49 Front-Room user.debug kernel: sd 0:0:0:0: [sda] Mode Sense: 38 00 00 00
    Dec 31 17:00:49 Front-Room user.err kernel: sd 0:0:0:0: [sda] Assuming drive cache: write through
    Dec 31 17:00:49 Front-Room user.err kernel: sd 0:0:0:0: [sda] Assuming drive cache: write through
    Dec 31 17:00:49 Front-Room user.info kernel: sda: sda1 < sda5 >
    Dec 31 17:00:49 Front-Room user.notice kernel: sd 0:0:0:0: [sda] Attached SCSI disk
    Dec 31 17:00:49 Front-Room user.warn kernel: fuse init (API version 7.8), DCACHE_BUG enabled
    Dec 31 17:00:50 Front-Room cron.info crond[631]: crond: crond (busybox 1.18.5) started, log level 8 Dec 31 17:00:51 Front-Room user.debug init[1]: starting rstats.
    Dec 31 17:00:51 Front-Room daemon.notice ntfs-3g[635]: Version 2011.4.12 integrated FUSE 27
    Dec 31 17:00:51 Front-Room daemon.notice ntfs-3g[635]: Mounted /dev/sda5 (Read-Write, label "HP Personal External Media Drive", NTFS 3.1)
    Dec 31 17:00:51 Front-Room daemon.notice ntfs-3g[635]: Cmdline options: iocharset=utf8,noatime,nodev
    Dec 31 17:00:51 Front-Room daemon.notice ntfs-3g[635]: Mount options: iocharset=utf8,nodev,allow_other,nonempty,noatime,fsname=/dev/sda5,blkdev,blksize=4096
    Dec 31 17:00:51 Front-Room daemon.notice ntfs-3g[635]: Ownership and permissions disabled, configuration type 1
    Dec 31 17:00:51 Front-Room user.info hotplug[525]: USB ntfs fs at /dev/sda5 mounted on /tmp/mnt/HP_Personal_External_Media_Drive
    Dec 31 17:00:51 Front-Room user.debug init[1]: starting cstats.
    Dec 31 17:01:08 Front-Room user.info kernel: br0: port 2(eth1) entering disabled state
    Dec 31 17:01:08 Front-Room user.info kernel: br0: port 2(eth1) entering forwarding state
    Dec 31 17:01:08 Front-Room user.info kernel: br0: port 3(eth2) entering disabled state
    Dec 31 17:01:08 Front-Room user.info kernel: br0: port 3(eth2) entering forwarding state
    Dec 31 17:01:09 Front-Room user.info init[1]: Linksys E3000: Tomato 1.28.7495 MIPSR2-Toastman-RT K26 USB Ext
    Dec 31 17:01:17 Front-Room daemon.err nmbd[658]: Samba server FRONT-ROOM is now a domain master browser for workgroup HOME-SYSTEM on subnet 192.168.2.11
    Dec 31 17:01:32 Front-Room daemon.err nmbd[658]: Samba name server FRONT-ROOM is now a local master browser for workgroup HOME-SYSTEM on subnet 192.168.2.11
     
  32. Planiwa

    Planiwa LI Guru Member

    Doesn't seem to have run yet. Can you please paste:

    Code:
    date
    l /var/spool/cron/crontabs/root
    cat /var/spool/cron/crontabs/root
    
     
  33. jsmiddleton4

    jsmiddleton4 Network Guru Member

    Wed Dec 31 17:17:13 UTC 1969
    -rw-r--r-- 1 root root 62 Dec 31 17:06 /var/spool/cron/crontabs/root
    0 */1 * * * logger -p syslog.info -- -- MARK -- #syslogdmark#
     
  34. Planiwa

    Planiwa LI Guru Member

    Hm. and this:

    l /tmp/sch_*
    cat /tmp/sch_*
     
  35. jsmiddleton4

    jsmiddleton4 Network Guru Member

    ls: /tmp/sch_*: No such file or directory
    cat: can't open '/tmp/sch_*': No such file or directory
     
  36. jsmiddleton4

    jsmiddleton4 Network Guru Member

    Thanks for your time and work. You've gone way above and beyond.
     
  37. Planiwa

    Planiwa LI Guru Member

    Well, I have been able to reproduce your result.

    When you set up the Custom script in Administration > Scheduler, be sure to:

    1. check Enable
    2. check the Time schedule (i.e. every minute for testing, every hour later).
    3. check each and every weekday as well as Everyday
    Scroll down to the bottom, where it says [Save]
    Observing carefully, click on [Save] . . .
    you should see: [Saving] and then [Some services are being restarted]

    Be sure you see both of these advisories after clicking on [Save]
     
  38. jsmiddleton4

    jsmiddleton4 Network Guru Member

    Did all that.
     
  39. Planiwa

    Planiwa LI Guru Member

    Hm. Ok. Here is the ultimate magic spell:

    In the INIT script:
    Code:
    cru a SetDate '0 * * * *  date -u -s $(wget http://tsmr.org/date.php -O - 2>&1 | sed -n '/UTC/s/UTC//p')'
    
    You will then be able to verify it with:
    Code:
    grep SetDate /var/spool/cron/crontabs/root
    
    which should show:
    Code:
    0 * * * *  date -u -s $(wget http://tsmr.org/date.php -O - 2>&1 | sed -n /UTC/s/UTC//p) #SetDate#
    
    This will set the date & time every hour, on the hour.
     
  40. jsmiddleton4

    jsmiddleton4 Network Guru Member

    I'm putting the first command line in the init script section, booting, then running the second command line from Tools System Execute?
     
  41. jsmiddleton4

    jsmiddleton4 Network Guru Member

    Will check it in an hour.
     
  42. jsmiddleton4

    jsmiddleton4 Network Guru Member

    Pulling script. Currently when I log on here it wants my router log on.
     
  43. jsmiddleton4

    jsmiddleton4 Network Guru Member

    Not sure why but one of my posts was redirecting to my router. Weird.

    Put script back in init.
     
  44. jsmiddleton4

    jsmiddleton4 Network Guru Member

    Worked......
     
  45. Planiwa

    Planiwa LI Guru Member

    Bravo! :)
     
  46. jsmiddleton4

    jsmiddleton4 Network Guru Member

    Had to get to bed last night after waiting to see if it worked. The last 25 lines of my log are all the same.

    Feb 9 07:00:01 Front-Room cron.info crond[641]: crond: USER root pid 2229 cmd date -u -s $(wget http://tsmr.org/date.php -O - 2>&1 | sed -n /UTC/s/UTC//p)

    You've done more than enough and as such I hesitate to ask. But here goes.

    1. What does the script need to be to check the time at boot up or once every 24 hours?
    2. Is there a way to use a public NTP server so the script doesn't rely on your mason lodge web site?
     
  47. jsmiddleton4

    jsmiddleton4 Network Guru Member

    Also was wondering given that with your scripts the slave router can in fact connect to the internet and get the time it not being able to do so normally is an indication that something is amiss with the firmware for this function when in wireless ethernet bridge mode?
     
  48. Planiwa

    Planiwa LI Guru Member

    #1 -- Make two cron entries, the first to run every 5 minutes in 1969 and 1970, and the second to run daily each year.

    #2 -- Some of us have found the (suboptimally formatted) USNO site, but nothing better. Some of us have concluded that in the absence of a web page that provides this functionality, it is easiest to create one. The originator of this thread has (also) created such a web page and has (also) offered to let you use it. This appears to solve the OP's problem, who stated explicitly that he could only use ports 80 and 443, and therefore not the NTP port. It also appears to solve (or work around) your problem.
     
  49. Planiwa

    Planiwa LI Guru Member

    Perhaps a new thread? Suitably titled, stating the problem, with facts about symptoms , findings, and configuration. (After thorough NVRAM erase, etc.)
     
  50. jsmiddleton4

    jsmiddleton4 Network Guru Member

    I have made topic specific thread about this matter but it ends up with the problem is me and my configuration. It isn't. My humble opinion is that the code for wireless ethernet bridge mode is built on an assumption which is the slave in bridge mode only requires the bare minimums in functions/features. It is after all a basically stupid bridged device. I understand the assumption. The master does all the heavy lifting.
     
  51. reddwarf

    reddwarf Networkin' Nut Member

  52. jsmiddleton4

    jsmiddleton4 Network Guru Member

    I've half wondered with the extra space available with an attached device or even memory if we could load our own ntp software.

    I'd much rather have whatever the issue is with ethernet bridge mode not setting the time be fixed however. :)
     
  53. Monk E. Boy

    Monk E. Boy Network Guru Member

    Looks cool, but you need an RS232 port, which isn't found on most consumer class hardware... well, at least not without modification. The USB port is just to supply 100mA power.

    Still a very cool idea though.
     

Share This Page