Operating System - Linux
1827881 Members
1334 Online
109969 Solutions
New Discussion

Re: How to schedule work in every two hours? two days? etc

 

How to schedule work in every two hours? two days? etc

I only knew to schedule system work in every one hour,one day,one week by cron, but actually have no idear in every two, or three.
Can cron do on this way? how?

thanks for your tips
Fredeirck van targero
4 REPLIES 4
Steven E. Protter
Exalted Contributor

Re: How to schedule work in every two hours? two days? etc

No problem at all

30 4,16 * * * /usr/contrib/bin/mirror.sites 2>&1 | mail -s "merijn mirror" your@mail.com


that does a job at 4 am and 4 pm 20 minutes after the hour

change it to:

30 0,2,4,6,9,10,12,14,16,18,20,22 * * * /usr/contrib/bin/mirror.sites 2>&1 | mail -s "merijn mirror" your@mail.com

Now the job runs every two hours in this case at 30 minutes after the hour

The next feild is day of the mont, that asterisk after the 22

pick your days again

30 4 2,4,6,8,10 * * /usr/contrib/bin/mirror.sites 2>&1 | mail -s "merijn mirror" your@mai.com

This runs a job every two days the first 10 days of the month at 4:30 a.m.

All this is fron the wonderful man crontab

My examples email the output as well.

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
Muthukumar_5
Honored Contributor

Re: How to schedule work in every two hours? two days? etc

Based on the following setting's,
minute 0-59
hour 0-23
day of month 1-31
month 1-12 (or names, see below)
day of week 0-7 (0 or 7 is Sun, or use names)

we can schedule the task execution on cron jobs.

To execute every two hours of one task the,

0 0,2,4,6,8,10,12,14,16,18,20,22 * * * command > (redirection)

Example:
0 0,2,4,6,8,10,12,14,16,18,20,22 * * * uname -a > 1>/tmp/uname.log 2>&1

To excute it on two days once then,
0 10 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29 * * uname -a > 1>/tmp/uname.log 2>&1

It will execute the task at 10.00 on 1,3,.. days of everymonth

Depends upon the setting we can execute tasks with cron.
Easy to suggest when don't know about the problem!
Stuart Browne
Honored Contributor

Re: How to schedule work in every two hours? two days? etc

Most modern linux based cron's have the ability first introduced with Vixie cron, and that is:

*/

i.e. to perform something every 2 hours, isntead of having a comma-separated-list like SEP suggests (there's nothing wrong with that btw):

15 */2 * * * /path/to/command

Which translates to the comma-separated-list of 0,2,4,6,8,10,12,14,16,18,20,22 - every 2 hours.

It works with all fields in the time specifier.
One long-haired git at your service...
Senthilmurugan
Frequent Advisor

Re: How to schedule work in every two hours? two days? etc

Cron do the job with the following format:

minute 0-59
hour 0-23
day of month 1-31
month 1-12 (or names)
day of week 0-7 (0 or 7 is Sun, or use names)


If you want to schedule a work for every 2 hour s you can do that by

* */2 * * * /PATH/TO/COMMAND

To schedule for every 2 days:
* * */2 * * /PATH/TO/COMMAND

See "#man 5 crontab" for more details.

Regards,
Senthil Murugan