4

There is a record:

45 * * * 1 script.sh

and

45 0-23 * * 1 script.sh

The desired effect is to run the script 45 minutes after every hour on Mondays.

Are they identical? If not, what is the difference?

  • 3
    If you remember that the 2nd field is "hours", the 1st is shorter; if you like seeing a reminder, the 2nd is more obvious. – Jeff Schaller Jul 18 '17 at 11:15
5

Yes, they are identical.

I'd suggest the first syntax as it is more concise.

3

They both work. However, I would personally prefer:

45 * * * mon script.sh

As it is more readable, and more immediately understandable without having to remember which day of the week is '1'.

  • 2
    Note that mon as a day name is a GNU extension to standard crontab. It's not likely available on non-GNU systems. – Andrew Henle Jul 18 '17 at 11:13
  • Agreed, but nearly all systems use Vixie/ISC cron (or GNU cron if you prefer). That covers Linux and BSD pretty well. – Bob Eager Jul 18 '17 at 11:25
0

They are identical but prefered to use first variant, there is less chance to get confused. Generally with its syntax is easy to get confused, here is a some typical mistakes with cron.

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.