57

The first noncomment line in a legacy crontab file begins with five asterisks:

* * * * * ([a_command]) >/dev/null 2>&1

The authors are gone, so I do not know their intent. What does all-wildcards mean to (Solaris 8) cron? The betting here is either run once, run continuously, or run never, which is unfortunately broad.

If you are wondering about the comment line preceding this, it is "Do not delete."

Note: This cron file is working. This question is not a duplicate of a question about broken cron files or cron files which require troubleshooting.

  • 4
    Something else to note, since it tripped me up severely at work recently: the >/dev/null 2>&1 section feeds all output from STDOUT and STDERR to /dev/null. The reason this is done: If you don't, then output from the program called in crontab will be mailed to the local mailbox of the user. Before I knew this I filled up a hard drive on a production server from a script running every two minutes. – Luke has no name Jul 24 '10 at 7:16
  • Thanks, Luke has no name; I had mis-attributed it to over-fussiness. – Thomas L Holaday Aug 18 '10 at 19:36
  • It looks like it qualifies to me. The answer explains how crontab works, and as it explains, this would run once every minute. The marking as duplicate is not meant to disparage your question, but to collect the commonly asked questions about cron, and their answers, in a single place. – Michael Hampton Jun 11 '14 at 0:20
56

Every minute of every day of every week of every month, that command runs.

man 5 crontab has the documentation of this. If you just type man crontab, you get the documentation for the crontab command. What you want is section 5 of the manual pages which covers system configuration files including the /etc/crontab file. For future reference, the sections are described in man man:

   1   Executable programs or shell commands
   2   System calls (functions provided by the kernel)
   3   Library calls (functions within program libraries)
   4   Special files (usually found in /dev)
   5   File formats and conventions eg /etc/passwd
   6   Games
   7   Miscellaneous  (including  macro  packages and conven‐
       tions), e.g. man(7), groff(7)
   8   System administration commands (usually only for root)
   9   Kernel routines [Non standard]
| improve this answer | |
  • 10
    +1 for the answer, -1 for the man cron comment. man pages are notoriously hard to read and understand for the beginner - that's why people come here, to have the man pages explained to them. – Mark Henderson Jul 20 '10 at 21:25
  • 4
    Totally, because it should have been man 5 crontab. That manpage is more specific and very easy to understand. See: linux.die.net/man/5/crontab – Warner Jul 20 '10 at 21:34
  • 6
    That's fine, provided the user is aware that the 5 is even relevant. Most new or part time Linux users don't know what number, if any, to use to access man pages. – John Gardeniers Jul 20 '10 at 21:43
  • 3
    @John, to prove your point, as someone who only dips their toe into *nix when I need to restart the occasional apache server, I was not even aware you could do a man 5 and I have no idea what would happen if I did... – Mark Henderson Jul 21 '10 at 3:19
  • 1
    -1 for the man cron also. I just googled the answer since it is faster than digging through the RAW man page. I also was worried it would be a special meaning that I would miss. Think about who will read your answer, we're not reading it to learn about the documentation but to know an answer to a question. – Aki Oct 1 '13 at 17:01
34

* = always. It is a wildcard for every part of the cron schedule expression.

So * * * * * means every minute of every hour of every day of every month and every day of the week.

 * * * * *  command to execute
 ┬ ┬ ┬ ┬ ┬
 │ │ │ │ │
 │ │ │ │ │
 │ │ │ │ └───── day of week (0 - 7) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0)
 │ │ │ └────────── month (1 - 12)
 │ │ └─────────────── day of month (1 - 31)
 │ └──────────────────── hour (0 - 23)
 └───────────────────────── min (0 - 59)

The nice drawing above is provided by wikipedia

An other example:

0 * * * * -this means the cron will run always when the minutes are 0 (so hourly)
0 1 * * * - this means the cron will run always at 1 o'clock.
* 1 * * * - this means the cron will run each minute when the hour is 1. So 1:00, 1:01, ...1:59.

| improve this answer | |
  • Man that really makes sense to me now. Thanks for the explanation. – Vishal Jul 28 '17 at 13:39
  • Isn't the sixth column for username as which to run the command? I've always wondered how does cron distinguish the command from the user, if there is space in between, like * * * * * php /var/myscript.php - how cron knows if php is part of command and not a username? – JustAMartin Nov 19 '17 at 0:08
  • @JustAMartin check this answer. The cron jobs created with crontab command seems to be linked to the user and do not need the sixth column for user. – Mohammad Faisal Feb 12 at 9:21
10
First star = Minutes: 0-59
Second star = Hours: 0-23
Third star = Day of Month: 0 - 31
Fourth star = Month: 0 - 12
Fifth star = Day of Week: 0 - 6 (0 means sunday)

Say you want to run something every 1st of every month.

0 0 1 * * something.sh
| improve this answer | |
  • 1
    That means to run something every minute of every hour on the 1st of every month (that would be 1440 times on day 1). – Kevin Brock Jul 21 '10 at 4:41
  • Oh yeah, let me edit that. – Michael Burns Jul 21 '10 at 18:37

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