cancel
Showing results for 
Search instead for 
Did you mean: 
jeesshnasree
Flight Engineer
Flight Engineer
  • 242 Views

custom cron job execute every day specific duration from Day 1 to Day 2

Hello All,

 

I am learning for cron script & specific duration execution in Day-1 post 8 PM & Day-2 pre 6 AM .

Actually my intension is cron script execute every day but time interval is 8 PM to 6 AM .

------------------------------------------------

script start time & day

Day-1 - 8 PM 

script end time & day

Day-2 - 6 AM

--------------------------------------------------

Script should run during this period from "Day-1 - 8 PM " to "Day-2 - 6 AM"

 

Cron script should start at 8 PM in Day-1 and execute upto 6 AM in Day-2 .

Post 6 AM that script should be stop .

Script should run every day between 8 PM in Day-1 upto  6 AM Day-2 .

 

Please provide me if cron script above mentioned criteria if possible .

 

I am waiting for your valuable . Please check and help me .

 

Regards,

JEESSHNASREE

0 Kudos
2 Replies
jodek
Cadet
Cadet
  • 197 Views

Yes, cron script above mentioned criteria is possible. You'll need to set up two separate cron entries: one for the period between 8 PM and midnight of Day-1, and another for the period between midnight and 6 AM of Day-2.

This is how it will look like:

For the period between 8 PM and midnight of Day1:

0 20 * * * /path/to/your/script.sh

For the period between midnight and 6 AM of Day2:

0 0-5 * * * /path/to/your/script.sh

 

 

 

 

0 Kudos
Fran_Garcia
Starfighter Starfighter
Starfighter
  • 140 Views

OP's problem description doesn't make too much sense taking into account the way cron works. Cron doesn't check how long a script takes to run, not it monitors or knows how to gracefully stop it, restart it in case it's not running or controls that is is not launched multiple times simultaneously.

 

Your proposal, while good, doesn't address these points. What if the script launched at 20:00 exists after a few minutes? Should it be restarted? if so, how often? does it matter that a pevious launch from 20:00 is still running? etc.

 

tldr: more details are needed, and probably they are not solved with cron.

0 Kudos
Join the discussion
You must log in to join this conversation.