I'm always amazed when I learn something new about a tool that I've been using for a rather long time. Take for example, cron. Not your run of the mill, everyday cron. I'm talking about the smarter cron that comes with most Linux distributions nowadays: Vixie cron.

(Vixie cron is named after Paul Vixie, the creator of BIND and other Unix goodness.)

While looking at the manual page for the crontab file format, I discovered a chunk that I'd never seen before:

  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 * * * *".

Hmm. @reboot. Isn't that handy. There's an easy way to give users the ability to run something at boot time without root access.

Posted by jzawodn at October 19, 2003 06:19 AM

Reader Comments
# Luke said:

Well I'll be damned. I've used cron for probably a decade and never knew - nice catch there :-)

on October 19, 2003 10:04 AM
# Sockitume Yusogoodtume said:

What man page is that on? Me no see it.

on October 19, 2003 11:47 AM
# dws said:

Neat, though I like to stagger-start my nightly cleanup tasks. @reboot solves a problem, though.

on October 19, 2003 12:43 PM
# Ben said:

I only came across that too about a month ago:

http://ben.milleare.com/archives/000171.html

It's amazing the things we miss :-)

on October 19, 2003 03:31 PM
# Luke said:

Sockitume: Do a "man 5 crontab".

on October 19, 2003 03:57 PM
# Peter Grigor said:

The only cron job I can think of to run at roboot as a user would be:

echo "Manage the server better!" | mail admin@myhost.com

:)

on October 19, 2003 04:17 PM
# Sockitume Yusogoodtume said:

I don't see anything in "man 5 crontab" (or the other man pages for that matter). It says 24 Jan 1994 at the bottom, maybe there's a new version.

on October 19, 2003 07:44 PM
# Draco said:

It's curious to see that's documented in FreeBSD but undocumented in Linux, despite the fact that the both use Vixie's cron. I use @reboot to run fetchmail on startup and to receive notifications about unexpected reboots...

on October 20, 2003 12:56 AM
# Jeremy Zawodny said:

Draco:

What distro are you using? It's clearly there on my Debian box(es).

on October 20, 2003 03:33 AM
# Draco said:

Jeremy: The distro is Red Hat 9 and there is no mention about @frequency features in crontab(5). But you're completely right, It appears in Debian's man pages. Sometimes I forget how different Linux distros are.

on October 20, 2003 05:43 AM
# Stanley Forbes-Winterbottom said:

it doesn't appear in the Mandrake man pages either. great tip btw.

on October 21, 2003 04:46 AM
# Bruno Vernay said:

So what is the "easy way to give users the ability to run something at boot time without root access" ??
At login time I know there is .bash_profile, then .xinitrd or kde/autostart/ ... but at boot time ??
Thanks
Bruno

on March 21, 2005 07:10 AM
# Bart Hawley said:

Yes.

This is perfect for those users that want their mudd to autostart after a reboot without giving them any root access to start it.

I run a teamspeak server and it has to start as a user, but not as root. It rarely ever dies, but the crontab I made was always trying to start it at intervals. This will start it once and be done.

on October 26, 2005 11:46 AM
# Rob said:

@reboot reboot


-Rob

on May 11, 2007 11:49 AM
# Ludvig Ericson said:

To all those who suggest using @reboot to do start-up things:

Most modern GNU/Linux distributions have /etc/init.d/ or something like it, which is a collection of scripts controlling various services.

For example, on a Gentoo box, you could do:
/etc/init.d/apache2 restart
And it'd restart Apache.

You can add your own of these, which should be a whole lot cleaner, and of course, these can be scheduled to be run at system start - that's half their point.

They'll also allow you to set up dependencies, so that you might load your TeamSpeak server after the PostgreSQL database has started. (Not that TeamSpeak currently supports PostgreSQL, but you get my point.)

on September 17, 2007 04:25 PM
# Albert Peschar said:

@Ludvig

You can only do that if you're root.

on December 30, 2007 12:10 PM
# said:

Please be aware that the 'reboot' doesn't happen when the machine boots up - it happens when cron boots up.

/etc/init.d/cron stop
/etc/init.d/cron start

on May 13, 2008 01:19 AM
# Jay said:

Who says you have to use this in the root crontab? A normal user can have a crontab and use the @reboot.

on July 10, 2008 06:29 AM
Disclaimer: The opinions expressed here are mine and mine alone. My current, past, or previous employers are not responsible for what I write here, the comments left by others, or the photos I may share. If you have questions, please contact me. Also, I am not a journalist or reporter. Don't "pitch" me.

 

Privacy: I do not share or publish the email addresses or IP addresses of anyone posting a comment here without consent. However, I do reserve the right to remove comments that are spammy, off-topic, or otherwise unsuitable based on my comment policy. In a few cases, I may leave spammy comments but remove any URLs they contain.