1847330 Members
2193 Online
110264 Solutions
New Discussion

cron jobs

 
Deepu Chakravarty
Regular Advisor

cron jobs

How to submit a cron job which runs through like following:

1. it should run everyday
2. it should run from 3a.m. to 12 midnight every minute.
OR
it should run from 4p.m. to 12 midnight every minute
OR
it should run from 3.10 p.m. to 11.35 p.m. midnight every minute or every hour
14 REPLIES 14
Bruno Ganino
Honored Contributor

Re: cron jobs

You must to use cron with "at" command.
See "at" on man.
Regards
Bruno
Torino (Turin) +2H
Shaikh Imran
Honored Contributor

Re: cron jobs

Hi,
It can be done by
create a file in
/var/spool/cron/crontabs

#minute hour monthday month weekday cmd

* 3 * * *

Now submit the cron job by
crontab /var/spool/cron/crontabs/.
Not sure about the values for your case but the method is this.
The above values are a guess for you case pls try it

Regards,




I'll sleep when i am dead.
John Carr_2
Honored Contributor

Re: cron jobs

Hi

you can achieve it using the same job in several lines

0-59 15-23 * * 1 myjob.sh
0-59 16-23 * * 2 myjob.sh

this example would run myjob each minute interval from 3pm to midnight on a Monday then from 4pm to midnight on a tuesday

:-) John.
John Carr_2
Honored Contributor

Re: cron jobs

use crontab -e to create cronfile for schedule.

John.
Ernesto Cappello
Trusted Contributor

Re: cron jobs

Hi.
You have to put in your crontab something like this:


10 15 1,2,3,4,5,6,7,8 * * * "your_command"

"your_command" should run from 15.10 until 23.10, would have to run every 1 hours!

For further information look "man crontab".

Regards Ernesto.
Mobeen_1
Esteemed Contributor

Re: cron jobs

Deepu,
The easiest way would be to put up a job in cron to run every day and in that script you check for times 3.00am to 12 midnight or the other options that you want.

As some one has mentioned, you should look at using 'at' command

regards
Mobeen
Jeroen Peereboom
Honored Contributor

Re: cron jobs

L.S.

to be honest I do not understand the question. What do you mean with the OR's in your question? How do you determine if the job should be started according to condition 2a OR 2b OR 2c?

JP.
Kiyoshi Miyake
Frequent Advisor

Re: cron jobs

hi,

> it should run from 3a.m. to 12 midnight every minute.

* 3-11 * * * command

with this config, command run at 3:00, 3:01, 3:02,... - 11:59.

> it should run from 4p.m. to 12 midnight every minute

* 16-23 * * * command

> it should run from 3.10 p.m. to 11.35 p.m. midnight every minute or every hour

you should set three line config.

10-59 15 * * * command
* 16-22 * * * command
0-34 23 * * * command

thanks.
Deepu Chakravarty
Regular Advisor

Re: cron jobs

Hi, Jeroen,
'OR' I mean if any condition I use in crontab. That's all. Not necessary that I will use all the 'OR' conditions in crontab. Actually I want to know commands at different situations.

Deepu Chakravarty
Regular Advisor

Re: cron jobs

Hi,
Ernesto,
I tried your command. It is not working. Pls suggest something else.
Thanks.
Mark Grant
Honored Contributor

Re: cron jobs

Ernesto's command is probably a typo. There are six fields in a crotnab entry and that one has seven.

You can not do this with one cron entry youwill have to use several as John mentions above.

However, the format of a crontab is like this

MIN HOUR DAY MONTH DAYOFWEEK (0 is Sunday) COMMAND

So your first example would be

0-59 3-23 * * * command

The second one would be

0-59 16-23 * * * command

For once an hour between 3pm and 10pm you'd do something like

0 15-20 * * * command
Never preceed any demonstration with anything more predictive than "watch this"
Richard Darling
Trusted Contributor

Re: cron jobs

Here is a tip I have been using for years to remember the syntax of cron. I add it to the top of the jobs:
#minute (0-59),
#| hour (0-23),
#| | day of the month (1-31),
#| | | month of the year (1-12),
#| | | | day of the week (0-6 with 0=Sunday).
#| | | | | commands
#0 2 * * 0,4 /rcd/scripts/myjob
Richard Darling
Trusted Contributor

Re: cron jobs

Sorry about the formatting - here it is as an attachment with the proper spacing.
John Carr_2
Honored Contributor

Re: cron jobs

Hi

it seems you have been given a good explanation of how cron works maybe if you could tell in more detail what you are trying to achieve we can help you with a working solution.

:-) John.