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?

1
  • 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. Commented Jul 18, 2017 at 11:15

3 Answers 3

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
  • 2
    Note that mon as a day name is a GNU extension to standard crontab. It's not likely available on non-GNU systems. Commented Jul 18, 2017 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. Commented Jul 18, 2017 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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.