12

It's not clear to be from the manpage for crontab. IS extra white space allowed between the fields? e.g., if I have this:

1 7 * * * /scripts/foo
5 17 * * 6 /script/bar
31 6 * * 0 /scripts/bofh

is it safe to reformat it nicely like this:

 1  7 * * * /scripts/foo
 5 17 * * 6 /script/bar
31  6 * * 0 /scripts/bofh

?

17

Yes extra space is allowed and you can nicely line up your fields for readability. From man 5 crontab

Blank lines and leading spaces and  tabs  are  ignored.

and

An environment setting is of the form,

   name = value

where the spaces around the equal-sign (=) are optional, and any  sub‐
sequent non-leading spaces in value will be part of the value assigned
to name.

For the fields itself the man pages says:

The fields may be separated  by  spaces or tabs.

That should be clear: multiple spaces are allowed.

  • +1 for having the actual quotes from the man page that I missed. space"S" – BIBD Sep 26 '14 at 13:45
15

Yes Extra whitespace is permitted. Consider:

#Mins  Hours  Days   Months  Day of the week
10     3      1      1       *       /bin/echo "I don't really like cron"
30     16     *      1,2     *       /bin/echo "I like cron a little"
*      *      *      1-12/2  *       /bin/echo "I really like cron"

I always add column headers because I'm too lazy to remember the order of all the numbers, but here's what that crontab produces:

This crontab should echo "I really like cron" every minute of every hour of every day every other month(Every Even month). Obviously you would only do that if you really liked cron. The crontab will also echo "I like cron a little" at 16:30 every day in January and February. It will also echo "I don't really like cron" at 3:10 on the January 1st.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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