Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to start a script, which set the system time automatically after booting. I wrote the command date -s "12/31/12 23:59" in rc.d/rc.local. That didn't work. How to solve that?

share|improve this question

migrated from stackoverflow.com Sep 10 '12 at 22:14

This question came from our site for professional and enthusiast programmers.

    
All Linux distributions already sets the time. Maybe the battery to your RTC on the motherboard is low? –  Joachim Pileborg Sep 10 '12 at 6:35
    
@JoachimPileborg actually there is no RTC on my motherboard :) It's a embedded system board without RTC. –  Peter Sep 10 '12 at 6:43

3 Answers 3

You are probably running ntp and it is setting the system time. You can try removing ntpd from startup at boot and you're system time should be 12/31/12 23:59.

share|improve this answer
    
I think nothing is setting the time, cause the time is after boot ... 1970. –  Peter Sep 10 '12 at 6:31

If you are developing for an embedded target, you most likely are using BusyBox as your shell. If you read the BusyBox command documentation you will see this for the date command:

Recognized TIME formats:

       hh:mm[:ss]
       [YYYY.]MM.DD-hh:mm[:ss]
       YYYY-MM-DD hh:mm[:ss]
       [[[[[YY]YY]MM]DD]hh]mm[.ss]

So you have to change the date/time format you use in the command to one of the recognized.

share|improve this answer

If your system is running a version of cron that supports it (specifically Vixie cron), you can use @reboot in a cron job.

This is one of 8 special strings that it supports.

Quoting the crontab(5) man page (from my Ubuntu 12.04 system):

Instead of the first five fields, one of eight special strings may appear:

string         meaning
------         -------
@reboot        Run once, at startup.
@yearly        Run once a year, "0 0 1 1 *".
@annually      (same as @yearly)
@monthly       Run once a month, "0 0 1 * *".
@weekly        Run once a week, "0 0 * * 0".
@daily         Run once a day, "0 0 * * *".
@midnight      (same as @daily)
@hourly        Run once an hour, "0 * * * *".

Please note that startup, as far as @reboot is concerned, is the time when the cron(8) daemon startup. In particular, it may be before some system daemons, or other facilities, were startup. This is due to the boot order sequence of the machine.

This is far from being the only way to run something at boot time, but it's an alternative.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.