automatic NTP sync

Discussion in 'Networking' started by JimK, Aug 19, 2008.

  1. JimK

    JimK

    Joined:
    Aug 14, 2008
    Messages:
    218
    Likes Received:
    0
    Is there a way to get the AAOne to automatically sync its clock with an NTP server, say, every day, or every time I turn it on?
     
    JimK, Aug 19, 2008
    #1
  2. JimK

    dealersing

    Joined:
    Jul 17, 2008
    Messages:
    23
    Likes Received:
    0
    append the following line on /etc/rc.local

    Code:
    ntpdate 0.ca.pool.ntp.org 
    u can use any time server you want.

    It will perform time sync each time you boot up your machine.
     
    dealersing, Aug 19, 2008
    #2
  3. JimK

    JimK

    Joined:
    Aug 14, 2008
    Messages:
    218
    Likes Received:
    0
    Hey dealersing, I appreciate the reply. I edited rc.local and restarted the computer, but the clock is still off (I know I can fix it manually, but I want it automated). Is there supposed to be a certain time when it syncs or is it supposed to work when the computer starts up? If it's the latter, I think it doesn't work because there's no Internet connection for several seconds after startup. Is there a workaround?
     
    JimK, Aug 19, 2008
    #3
  4. JimK

    Sid

    Joined:
    Jul 22, 2008
    Messages:
    632
    Likes Received:
    0
    Location:
    UK - (most locations)
    Sid, Aug 19, 2008
    #4
  5. JimK

    dealersing

    Joined:
    Jul 17, 2008
    Messages:
    23
    Likes Received:
    0
    I haven't use linux for such a long time and I pretty much forgot everything I learnt from the past. I remember i used to run cron job to have the time sync every hour.

    http://linuxreviews.org/howtos/ntp/

    3.3 will show you how to add the hourly cron job. Hope that helps. :)
     
    dealersing, Aug 19, 2008
    #5
  6. JimK

    JimK

    Joined:
    Aug 14, 2008
    Messages:
    218
    Likes Received:
    0
    Thanks! It worked. With that link and a little Googling, I managed to create a time.cron file in /etc/cron.hourly and it adjusted my clock perfectly. I love it when stuff works like it's supposed to.
     
    JimK, Aug 19, 2008
    #6
  7. JimK

    Sid

    Joined:
    Jul 22, 2008
    Messages:
    632
    Likes Received:
    0
    Location:
    UK - (most locations)
    Great stuff, thanks for reporting back.

    Does anyone want to define a way to run a cron job at a set time (delay) after booting and then never run it again?

    To be clear, the requirement is:
    The One system boots,
    waits two minutes (for the network to connect),
    runs an ntp update just once, unless rebooted.
     
    Sid, Aug 19, 2008
    #7
  8. JimK

    rbil

    Joined:
    Aug 14, 2008
    Messages:
    730
    Likes Received:
    0
    Location:
    The Wet Coast, Canada
    Don't think you can setup a cronjob to do that, as they are only defined as hourly, daily, weekly, monthly. Look at an earlier post of setting up to do the job when you login, as that would happen just after booting.

    Cheers.
     
    rbil, Aug 19, 2008
    #8
  9. JimK

    JimK

    Joined:
    Aug 14, 2008
    Messages:
    218
    Likes Received:
    0
    The problem with the login job is that the AAOne logs me in several seconds before I get a wireless Internet connection. The network connection appears to be the last thing it does, so it wouldn't be able to sync with the time server as part of login.
     
    JimK, Aug 19, 2008
    #9
  10. JimK

    Sid

    Joined:
    Jul 22, 2008
    Messages:
    632
    Likes Received:
    0
    Location:
    UK - (most locations)
    How about using cron to run a script that checks system uptime and getting it to look at killing the previous cron job?


    Full of ideas huh?
     
    Sid, Aug 20, 2008
    #10
  11. JimK

    Bushmills

    Joined:
    Sep 5, 2008
    Messages:
    18
    Likes Received:
    0
    Location:
    Germany
    yes, you can (set up a cronjob to run once only): as activation time, give @reboot. as in:

    crontab -e ( as root, editing root's crontab, then add)
    @reboot ntpdate -b pool.ntp.org

    or, when adding to system crontab in /etc
    @reboot root ntpdate -b pool.ntp.org
     
    Bushmills, Sep 22, 2008
    #11
  12. JimK

    kevin

    Joined:
    Sep 18, 2008
    Messages:
    274
    Likes Received:
    0
    I think a better way to do this to launch ntpdate whenever a network connection is raised. Then you won't have to worry about whether your network connection settles in a particular time.

    I suppose, to be pedantic, you ought to do it only when a connection that goes to the Internet is raised, but that will be the default connection for most people.

    So all you need to do is create the following file as /etc/NetworkManager/dispatcher.d/01-nptpdate and chmod 755 it:

    #!/bin/bash
    if [ "$2" = "up" ]; then
    /usr/sbin/ntpdate {my_time_server}
    fi

    Hope this helps.
     
    kevin, Sep 22, 2008
    #12
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.