Run cron job every 2 minutes except the first minute "0" of the first hour "0"

Michael Samuel

I have a simple cron job inside cPanel that runs every 2 minutes:

*/2 * * * *

By default the "0" minute is the start of the cron job like 0,2,4,6,8,10 etc...

How to skip the "0" minute of the "0" hour (12AM) in the cron? I do this because this cron depends on another cron which runs once daily at 12AM. So I don't want them to overlap.

In short, I need this cron to run every 2 minutes except 00:00 at 12:00AM.

Giacomo1968

This is your cron job:

*/2 * * * *

But then you state:

How to skip the "0" minute of the "0" hour (12AM) in the cron? I do this because this cron depends on another cron which runs once daily at 12AM. So I don't want them to overlap.

The problem is not the cron job but rather your script logic. Perhaps you could do something like create some kind of indicator in the first job that the second job would pick up on so they don’t conflict.

Perhaps you should just change your cron to be the inelegant, but specific of every 2 minutes like this:

2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * *

One concept would be to combine an interval (2-58) with a frequency (*/2), but unclear if this could work.

2-58/2 * * * *

EDIT: According to the comment left by the original poster:

In short, I need this cron to run every 2 minutes except 12AM.

If that is the case, you might have to set a mix of cron jobs like this:

*/2 1-23 * * *
2-58/2 0 * * *

The first cron entry would run the job every 2 minutes from 1:00am to 11:00pm.

The next cron entry would run the job every 2 minutes from 2-58 minutes only at midnight. Since this second job skips 0 during the 0 hour of midnight this combo should work for you.

But that said, this kind of dual entry logic is why it’s actually encouraged that developers expand their app logic to avoid certain scenarios it won’t work.

For example, I have some bash scripts that create lock files in the standard Unix /tmp directory. They are set to run every 5 minutes, but the script itself has logic to make sure the first thing it does before anything is to check if that lock is present. If the lock is there? Do nothing. If the lock is not there, go nuts!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Run a cron job on the first Monday of every month?

Why does my cron job run every 1 minute although I set it every 1 hour?

Why my cron job is running every minute when it is scheduled to run every hour?

run cron every minute during a specific hour?

Run cron job every 2 hours In the X minute

Can a cron job be set to run every hour at 5 minutes after the hour?

How to run a cron job to execute every minute?

Run a cron job every minute, meaning of syntax

Why Angular-cron-jobs generates the same cron expression for "Every Minute", "Every Hour at 0 past hour","Every Day at 0:0" etc

Cron Job firing every minute for an hour at it's scheduled execution time

Run Cron every 2 minutes in 30 minutes?

Cron: Run every day except first day of the month and first day of each week

How to run a cron jobs in every minute for a specific hour on server

Run Cron Job Every 15 Minutes in specific time and every day

NSTimer run every minute but on first second

CRON: Difference between "At minute 0" and "Every 60 minute"

CRON expression : make last hour non exclusive at minute 0

How to set up a cron job to run an executable every hour?

How to run cron job every one hour and 10 min

cron expression to run a job every hour but only on weekdays?

Run a cron job every 5 minutes between two times

How would I get a cron job to run every 30 minutes?

Run Cron job every N minutes plus offset

Run Cron job every 10 minutes between two hours

Python - Run Job every first Monday of month

execute cron job every 2 hour with 30 min duration

Configure systemd timer to run every hour after first run

Build a cron job running first weekday of every 3 months

Running a cron job every 5 minute on arch

TOP Ranking

HotTag

Archive