Madhu CM
Madhu CM

Reputation: 2536

A cron job that will never execute

Is there any way to create a cron expression for not running the job at all?

I though of using this expression :

0 0 0 1 1 ? 3099

...which will practically do the job as it will run on year 3099, but is there a cleaner way to do it?

Upvotes: 140

Views: 147027

Answers (7)

Andrei Petrut
Andrei Petrut

Reputation: 420

I needed something similar with seconds included and I have used the DevToys app to generate a CRON expression that will happen very far in the future: https://devtoys.app/.

enter image description here

Upvotes: 2

Martin Cleaver
Martin Cleaver

Reputation: 1914

Pick a date in the past.

That'll never happen again. Unless it's groundhog day. Just don't pick groundhog day.

Upvotes: 67

Tim Iles
Tim Iles

Reputation: 2330

I needed a valid cron schedule (? syntax not working in my system) which resolves real dates, but to be effectively "never". My current best solution was to pick the most recent leap year and see what day Feb 29th fell on. Feb 29 2016 was a Monday, so the next Monday Feb 29 is currently furthest away.

0 0 29 2 1 yields the next 5 triggers as:

02/29/2044 00:00:00Z
02/29/2072 00:00:00Z
02/29/2112 00:00:00Z
02/29/2140 00:00:00Z
02/29/2168 00:00:00Z

Not perfect but it'll do.

Upvotes: 33

Eric Tjossem
Eric Tjossem

Reputation: 2706

If you're still looking for something robust even in the far future, try https://stackoverflow.com/a/13938099/1601531, where I suggest the use of February 31st in crontab entries which are never intended to execute.

0 0 5 31 2 ?

Upvotes: 155

Chop
Chop

Reputation: 4517

I created a duplicate (click here to see) for your question, and agree with your initial proposal. After testing, it appears Quartz will never execute a cron expression with a year above 2300.

Upvotes: 1

Michael Krelin - hacker
Michael Krelin - hacker

Reputation: 143061

Comment it out — put # sign in front of it. Very useful, especially if you're afraid you'll forget about your changes by the year 3099.

Another possibility is to make it execute dummy command, like true rm -rf /.

Upvotes: -14

aefxx
aefxx

Reputation: 25249

Opening your crontab file and deleting the entry would be the adequate way. Or you might as well simlink the executable that's called by the cronjob to an empty shell script.

Tell us more about your setup, then we'll see ...

Upvotes: -4

Related Questions