Operating System - Linux
1830168 Members
5010 Online
109999 Solutions
New Discussion

how to schedule the work in every two hours

 
SOLVED
Go to solution

how to schedule the work in every two hours

i tried many times by cron, but did not meet the expect. could any gentleman show me example?

thanks very much
frederick
6 REPLIES 6
Huc_1
Honored Contributor
Solution

Re: how to schedule the work in every two hours

Here is an example to do df every 2 hours.

to edit do crontab -e

add the following lines

00 2 * * * /usr/bin/df >> t.t
00 4 * * * /usr/bin/df >> t.t
00 6 * * * /usr/bin/df >> t.t
00 8 * * * /usr/bin/df >> t.t
00 10 * * * /bin/df >> t.t
00 12 * * * /bin/df >> t.t
00 14 * * * /bin/df >> t.t
00 16 * * * /bin/df >> t.t
00 18 * * * /bin/df >> t.t
00 20 * * * /bin/df >> t.t
00 22 * * * /bin/df >> t.t
00 00 * * * /bin/df >> t.t

this will run df every two hour and save output to file.

hope this not very usefull example will help you out.

J-P (Jean-Pierre)
Smile I will feel the difference
Huc_1
Honored Contributor

Re: how to schedule the work in every two hours

Did it again ! should read my answer before sending then !

In the crontab file the first lines should read

/bin/df

like in the last lines.

Please No points for this reply !

J-P (Jean-Pierre)
Smile I will feel the difference
Bojan Nemec
Honored Contributor

Re: how to schedule the work in every two hours

Frederick,

Acording to the crontab (5) man page the crontab entry can be:

0 0-23/2 * * * your2hourCommand
or
0 */2 * * * your2hourCommand
or
0 0,2,4,6,8,10,12,14,16,18,20,22 * * * your2hourCommand

I tested all 3 variants on the first field (minute) and they work.

Dont forget to finish the line with a new line! It seems that cron ignore lines which are not terminated by a linefeed

Bojan
Muthukumar_5
Honored Contributor

Re: how to schedule the work in every two hours

crontab entries can be defined to schedule work to be done in every two hours as,

0 0,2,4,6,8,10,12,14,16,18,20,22 * * *

where
first field indicates minute's
second one for hour setting

Example:
0 0,2,4,6,8,10,12,14,16,18,20,22 * * * date 1> /tmp/date_check 2>&1

* indicates that it will do in every day, every week-day and every month day's

Easy to suggest when don't know about the problem!
Fred Ruffet
Honored Contributor

Re: how to schedule the work in every two hours

As long as linux cron has more features in time definition, the more easy way will be :
00 */2 * * * myjob

It will then run at odd hours.
If you want it to run at even hours, use :
00 1-23/2 * * * myjob

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Senthilmurugan
Frequent Advisor

Re: how to schedule the work in every two hours

You can very well do the cronjob to be done for every 2 hours with the following entry in the cron list
Hello
Well you can do your job for every 2 hours using the cron.For this u can do the following in your command prompt:

#crontab -e
* */2 * * * /PATH/TO/COMMAND > /dev/null 2>&1


Now your job will be done for every 2 hours/

More can be available at:
#man 5 crontab

Regards,
Senthil Murugan