Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I schedule a task to run on next reboot?

I understand that we have tools like cron and at to help with scheduling. But they seem to allow scheduling at a specific time and not on specific event (like rebooting).

share|improve this question
add comment

1 Answer

You can use @reboot - from man crontab1:

The following formats are also recognized:
# schedule this job only once, when crond starts up
@reboot date

So you could use something like:

@reboot /path/to/yourtask

There are other Cron special keywords2:

Keyword Equivalent
@yearly 0 0 1 1 *
@daily 0 0 * * *
@hourly 0 * * * *
@reboot Run at startup.

[1] In dcron and Vixie cron

[2] http://www.thegeekstuff.com/2009/06/15-practical-crontab-examples/

share|improve this answer
    
You should first indicate what cron implementation you are referring to. –  rozcietrzewiacz Aug 29 '11 at 18:52
    
Note that @reboot will also get called when the cron daemon is restarted. Not sure if this is a bug, or by design. –  Stefan Lasiewski Aug 29 '11 at 19:40
    
@rozcietrzewiacz Updated. Stefan: yes, the man page quote makes that point. –  jasonwryan Aug 29 '11 at 20:46
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.