cancel
Showing results for 
Search instead for 
Did you mean: 

how to schedule job in crontab?

 
Highlighted
Occasional Advisor

how to schedule job in crontab?

hi,

how to schedule job in crontab for every 40 mins?

Thanks,
14 REPLIES 14
Highlighted
Trusted Contributor

Re: how to schedule job in crontab?

Hi,

make your crontab some thing like this:

0 0,3,6,9,12,15,18,21 * * *
40 1,4,7,10,13,16,19,22 * * *
20 2,5,8,11,14,17,20,23 * * *

Hope it will work as you want..
Highlighted
Honored Contributor

Re: how to schedule job in crontab?

Hi Friend,

Under /var/spool/cron/crontabs/

each user will have there own jobs. You may use the command

crontab -e and just put the entry like

# min 0-59 hour0-23 date1-31 month1-12 day0-6 command

You may see the examples given by Fayez

* Make sure that cron deamon is running
* /var/adm/cron/cron.allow and cron.deny is cofigured like the user can crate cronjobs.

crontab -r = Remove all your scheduled cronjobs:

crontab -l =
View your cronfile:


For making cron you may use

Edit and submit a cronfile:
# crontab-e

make sure that your editor variable is set for using the switch "e".

Regards,
Sooraj
"UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity" - Dennis Ritchie
Highlighted

Re: how to schedule job in crontab?

Before using the the command to edit as rightly said by Sooraj use :

# export EDITOR=vi
# crontab -e

where username would be the user through which you would want to run the cron job every 40 mins. e.g. root

Insert a new line entry such as below :

40 * * * *

Note : Ensure you maintain an equal space between arguments.
Highlighted
Exalted Contributor

Re: how to schedule job in crontab?

Shalom,

This document might be of additional assistance to you.

http://www.docs.hp.com/en/5991-6469/ch09s04.html

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Highlighted
Trusted Contributor

Re: how to schedule job in crontab?

Friend,

It is not good manner to leave your thread without replaying to people response, and without points, at least if response did not help, just tell so we can continue helping you.

If you keep like this in every thread you open, no one will help you in future. Sorry!!!
Highlighted
Honored Contributor

Re: how to schedule job in crontab?

"40 1,4,7,10,13,16,19,22 * * * "

-and-

"40 * * * * "

runs the job once an hour at 40 minutes after. Note the original request was "every 40 minutes". If that truly means you want 40 minutes to elapse between runs, the above isn't going to work.

Perhaps a bit of clarification is in order here?
Highlighted
Advisor

Re: how to schedule job in crontab?

Hi Friend :) ( nice name )
There is an Online document addressing EXACTLY what you might be looking for at

WITH EXAMPLES at

http://docs.hp.com/en/B2355-90164/apcs01.html

COPY PASTE FROM ABOVE LINK BELOW

<<>>>>

You can use the crontab command to run commands at regular intervals. For example, you can send a weekly e-mail reminder for a meeting to your mailbox, or erase all "tmp" files everyday.

The crontab command creates a file called by your username in the directory /var/spool/cron/crontabs. The commands in the file are executed at the specified intervals in your home directory.

A crontab file contains line with six fields each separated by spaces or tabs. The first five fields specify the time the command will be run

minute (0-59)
hour (0-23)
date of the month (1-31)
month of the year (1-12)
day of the week (0-6 with 0=Sunday)

The sixth field is a string that is executed at the appropriate time.

To create a crontab command file, enter:

$ crontab

Then type the commands you want to schedule and press Ctrl-D.

30 8 * * 4 echo "Staff meeting today at 10:00 AM"
0 0 * * * rm *.tmp 2 > errfile

Ctrl-D

The crontab file is interpreted as follows:

On Thursday at 8:30 AM, crontab sends you a reminder of your 10:00 AM staff meeting. The first field (30) indicates 30 minutes after the hour. The second field indicates the hour (8). The asterisks mean all legal values. The 4 means Thursday.

At midnight everyday, crontab erases files with a *.tmp extension in your directory. Error messages are redirected to a file called errmsg in your home directory.
List crontab

To list your current crontab entries, use the -l option.

$ crontab -l

<<<<<<<<<<<<<<<<<<<<<
Highlighted
Advisor

Re: how to schedule job in crontab?

Hi Friend,
i read it again and it's a very good question

your cron job would run after the following intervals

40 mins
80 mins
120 mins

so if you translate it into a time for argument sake this is what we get

1.40PM
2.20PM
3.00PM

3.40PM
4.20PM
5.00PM

5.40PM
6.20PM
7.00PM

7.40PM
8.20PM
9.00PM

Do you see a pattern so you have to write three cron jobs

minute The minute of the hour, 0-59

hour The hour of the day, 0-23

monthday The day of the month, 1-31

month The month of the year, 1-12

weekday The day of the week, 0-6, 0=Sunday


, to specify time as a number
- to give a range of time
* includes all the valid values in the feild


40 1,3,5,7 * * * echo "40 mins every odd hour"
the above line in crontab would run echo command at 01:40 PM - 03:40PM - 05:40PM - 07:40PM


20 2,4,6,8 * * * echo "20 mins every even hour"
the above line in crontab would run echo command at 02:20 PM - 04:20PM - 06:20PM - 08:20PM


00 3,5,7,9 * * * echo "run this every even hour"
the above line in crontab would run echo command at 03:00 PM - 05:00PM - 07:00PM - 09:00PM


this way you get to run this job every 40 mins - ofcourse you might want to replace the echo command with the relevent job's

<<< Please don't forget to assign points >>>>>>>>
Highlighted
Honored Contributor

Re: how to schedule job in crontab?

or you could run it every 20 minutes. the job would have to be modified to look for a lock file:

a) if found delete it an exit w/o processing
b) if not found create it and process

Of course, the operations could be swapped, as in

c) if found, process and delete
d) if not found, delete and exit