1836425 Members
2153 Online
110100 Solutions
New Discussion

Re: Crontab

 
SOLVED
Go to solution
O'lnes
Regular Advisor

Crontab

When setup a crontab job , can i exclude a period of time to run the schedule.

eg.

Run the schedule task from 9am to 17pm but except 1pm ??? 2pm

0,30 9-17 * * * schedule task
Andy
9 REPLIES 9
Stefan Farrelly
Honored Contributor

Re: Crontab

I dont think you can do it in one line. We have jobs like this and end up having to have 2 lines, eg, one for 9-1pm and one for 2pm-17
Im from Palmerston North, New Zealand, but somehow ended up in London...
Leif Halvarsson_2
Honored Contributor

Re: Crontab

Hi

0,30 9-12,15-17 * * * schedule task
or
0,30 9,10,11,12,15,16,17 * * * schedule task
Patrick Chim
Trusted Contributor

Re: Crontab

Hi,

I don't think it's possible to do.

As my opinion, I will either separate the cronjob into 2 time range or just skip your time range in your schedule task.

Regards,
Patrick
Dirk Wiedemann
Respected Contributor

Re: Crontab

Hello

workaround to your example: you need two crontab entries, one for 9-13 and one for 14-17.

regards
Dirk
Jim_116
New Member
Solution

Re: Crontab

Whilst cron is not designed to disallow certain times from its criteria, this may not be the best way of NOT running a script/program.

Maybe the alternative is to run the script/program but place the time check in the script/program itself??

The following could be placed in a script to stop a job running if the hour resturns as 10.

#!/bin/sh
TEST=`date +%H`
if [ $DATE = 10 ]
then
exit 1
else
run-job.sh
fi


Hope that helps. Thinking sideways is always an art form.

Jim
For what do you call an assassin who accuses and assassin anyway? My Friend..
Leif Halvarsson_2
Honored Contributor

Re: Crontab

Hi
Perhaps I have misunderstod something but I can't see why this should not could be done in one line.
I made a simple test (but with minutes instead of hours.


# crontab -l
10-15,51-54,56-59 * * * * date >>/tmp/abc
#
# cat abc
date
Fri Sep 13 03:51:01 MDT 2002
Fri Sep 13 03:52:00 MDT 2002
Fri Sep 13 03:53:00 MDT 2002
Fri Sep 13 03:54:00 MDT 2002
Fri Sep 13 03:56:00 MDT 2002
Fri Sep 13 03:57:00 MDT 2002
Fri Sep 13 03:58:00 MDT 2002
Fri Sep 13 03:59:00 MDT 2002
Fri Sep 13 04:10:00 MDT 2002
Fri Sep 13 04:11:00 MDT 2002
Fri Sep 13 04:12:00 MDT 2002
Fri Sep 13 04:13:00 MDT 2002
Fri Sep 13 04:14:00 MDT 2002
Dirk Wiedemann
Respected Contributor

Re: Crontab

Leif, you are absolut right. I've forgotten my brain at home today ;-)

Dirk
Allan Pincus
Frequent Advisor

Re: Crontab

Why wouldn't this work:

0,30 9-12,14-17 * * * myJob

or

0,30 9,10,11,12,14,15,16,17 * * * myJob

This should fire off at the 0 and 30 minutes of every hour 9, 10, 11, 12, then skip the 0 and 30 minutes of 1pm, then fire off the 0 and 30 minutes of 2pm, 3, 4, and 5.

I assume lunch hour is being skipped.

Am I missing something?

- Allan
Darrell Allen
Honored Contributor

Re: Crontab

Hi,

Leif's solution is simple, commonly accepted, and in a word "correct".

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)