Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to run a cron job every 5 min

90 views
Skip to first unread message

Hugh Kang

unread,
Apr 16, 2003, 8:59:36 AM4/16/03
to
I'd like to run a cron job every 5 min. In this case, I can modify the crontab
like "0,5,10,15,20, -> 55 * * * *" However, this is too long. Is there any other
way that I can simply make it?

Thanks in advance.

SK

Uli Wachowitz

unread,
Apr 16, 2003, 9:41:07 AM4/16/03
to
On Wed, 16 Apr 2003 14:59:36 +0200, Hugh Kang wrote:

> I'd like to run a cron job every 5 min.

man is your friend ;-)

*/5 * * * * YOUR_COMMAND

this will do the job.

--
M.C.S.E :- Minesweeper Consultant & Solitaire Expert
"GPG-KEY on demand"

André Stiehm

unread,
Apr 16, 2003, 9:47:21 AM4/16/03
to
Hi Hugh,
you can use

*/5 * * * *

With this entry, your job is running all five Minutes.

regards,
André

hymie!

unread,
Apr 16, 2003, 9:49:53 AM4/16/03
to
In our last episode, the evil Dr. Lacto had captured our hero,

sk...@leaguedata.com (Hugh Kang), who said:
>I'd like to run a cron job every 5 min. In this case, I can modify the crontab
>like "0,5,10,15,20, -> 55 * * * *" However, this is too long. Is there any other
>way that I can simply make it?

Check your man page to see if your version of cron and/or crontab supports
the */5 construct.

hymie! http://www.smart.net/~hymowitz hy...@lactose.smart.net
===============================================================================

Michael Fuhr

unread,
Apr 16, 2003, 10:08:58 AM4/16/03
to
Uli Wachowitz <u...@wach-o-witz.de> writes:

> On Wed, 16 Apr 2003 14:59:36 +0200, Hugh Kang wrote:
>
> > I'd like to run a cron job every 5 min.
>
> man is your friend ;-)
>
> */5 * * * * YOUR_COMMAND
>
> this will do the job.

Not every system supports this syntax. When giving an answer that's
system-dependent, it's a good idea to qualify it as such.

The OP should have indicated what system he's using, but since he
didn't, we don't know whether this will work for him or not.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

Randal L. Schwartz

unread,
Apr 16, 2003, 10:59:17 AM4/16/03
to
>>>>> "Uli" == Uli Wachowitz <u...@wach-o-witz.de> writes:

Uli> On Wed, 16 Apr 2003 14:59:36 +0200, Hugh Kang wrote:
>> I'd like to run a cron job every 5 min.

Uli> man is your friend ;-)

Uli> */5 * * * * YOUR_COMMAND

I prefer giving a start minute, so I can keep everything from hitting
at the top of the hour at once:

1-59/5 * * * * COMMAND

that fires at 1, 6, 11, 16 etc.

If I had another one, I use:

2-59/5 * * * * COMMAND

to fire at 2, 7, 2, 17, etc.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<mer...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Hugh Kang

unread,
Apr 16, 2003, 1:01:04 PM4/16/03
to
hy...@lactose.smart.net (hymie!) wrote in message news:<v9qns1b...@corp.supernews.com>...

I am with SCO UnixWare 7.1.1. "*/5" doesn't work on our system. I've got
"unexpected character found in line". I checked man crontab but it doesn't say
anything about it clearly. Anyone else please?

Thanks
Hugh

dave...@spamcop.net

unread,
Apr 16, 2003, 1:20:37 PM4/16/03
to
Someone who looks an awful lot like Hugh Kang <sk...@leaguedata.com> wrote:

> I am with SCO UnixWare 7.1.1. "*/5" doesn't work on our system. I've got
> "unexpected character found in line". I checked man crontab but it doesn't say
> anything about it clearly. Anyone else please?

If your system's version of cron doesn't support that sort of thing, I
guess your two options are to live with it, or to build a version of
cron which does support it. Of the two options, I'd just deal with it,
personally.

Barry Margolin

unread,
Apr 16, 2003, 1:19:36 PM4/16/03
to
In article <257137ea.03041...@posting.google.com>,

Hugh Kang <sk...@leaguedata.com> wrote:
>I am with SCO UnixWare 7.1.1. "*/5" doesn't work on our system. I've got
>"unexpected character found in line". I checked man crontab but it doesn't say
>anything about it clearly. Anyone else please?

What can "anyone else" say? Either your system supports it or it doesn't.
If it doesn't, you go back to the standard syntax that you already know.

I suppose you could install the cron daemon from FreeBSD or Linux -- I
expect they will work in most other flavors of Unix as well.

--
Barry Margolin, barry.m...@level3.com
Genuity Managed Services, a Level(3) Company, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

Chuck Dillon

unread,
Apr 16, 2003, 4:05:12 PM4/16/03
to

You can make multiple entries that call the same thing at different times.

-- ced

--
Chuck Dillon
Senior Software Engineer
NimbleGen Systems Inc.

Rev. Don Kool

unread,
Apr 16, 2003, 4:18:35 PM4/16/03
to

Barry Margolin wrote:
> Hugh Kang <sk...@leaguedata.com> wrote:

>>I am with SCO UnixWare 7.1.1. "*/5" doesn't work on our system. I've got
>>"unexpected character found in line". I checked man crontab but it doesn't say
>>anything about it clearly. Anyone else please?

> What can "anyone else" say? Either your system supports it or it doesn't.
> If it doesn't, you go back to the standard syntax that you already know.
>
> I suppose you could install the cron daemon from FreeBSD or Linux -- I
> expect they will work in most other flavors of Unix as well.

It is bad form to troll in the technical newsgroups, Barry. As
"FreeBSD" and "Linux" aren't "flavors of Unix" (no matter how much
penguin heads wish they were), your expectations are far off the mark.

Happy to have cleared things up for you,
Don

--
*************************** Q: How many frenchmen does it take
* Rev. Don McDonald, SCNA * to defend Paris?
* Baltimore, MD * A: No one knows, it's never been tried.
***************************
http://mywebpages.comcast.net/oldno7/TheFrench.mpg
Reluctant Yamaha YZF-R1 Owner

Mark Rafn

unread,
Apr 16, 2003, 6:55:02 PM4/16/03
to
Hugh Kang <sk...@leaguedata.com> wrote:
>I'd like to run a cron job every 5 min. In this case, I can modify the crontab
>like "0,5,10,15,20, -> 55 * * * *" However, this is too long. Is there
>any other way that I can simply make it?

Too long for what? It's a fine, respectable syntax which works
on every cron implementation I know.

You've stated elsewhere that your cron does not support the */5 construct.
Other options are:

a Write a program which you can have cron run every minute, but only performs
the task every 5th invocation.

b Write a daemon that wakes up every 5 minutes and does your task. Run this
at startup.

c Install a different cron which supports a syntax you like better.

d Live with the verbose syntax in your crontab file.

e Live with your process running too often (every minute) or too rarely (every
hour).

f Hire local students to run your command every 5 minutes. Minimum wage
in many US locations will cost you less than $0.50 per invocation.

g Use at rather than cron. Your process can schedule its next invocation with
"echo runmeagain | at now + 5 minutes" each time it's run. There will be
a slight drift, but it won't be much if you reschedule before doing any
work.

h This task probably isn't that important. Run it yourself when needed. Each
time you do, you'll feel good because you just saved 50 cents ;)

If it were me, I'd go with d.

good luck!
--
Mark Rafn da...@dagon.net <http://www.dagon.net/>

Bill Marcum

unread,
Apr 16, 2003, 7:05:34 PM4/16/03
to
On 16 Apr 2003 05:59:36 -0700, Hugh Kang
<sk...@leaguedata.com> wrote:
> I'd like to run a cron job every 5 min. In this case, I can modify the crontab
> like "0,5,10,15,20, -> 55 * * * *" However, this is too long. Is
there any other
> way that I can simply make it?
>
Another way would be to write a script with "while sleep 300; do ..."


--
bill marcum the mushroom-eating laboratory monkey
What kind of monkey are you? http://thesurrealist.co.uk/monkey.cgi

hymie!

unread,
Apr 17, 2003, 8:56:31 AM4/17/03
to
In our last episode, the evil Dr. Lacto had captured our hero,
sk...@leaguedata.com (Hugh Kang), who said:
>hy...@lactose.smart.net (hymie!) wrote in message
>news:<v9qns1b...@corp.supernews.com>...
>> In our last episode, the evil Dr. Lacto had captured our hero,
>> sk...@leaguedata.com (Hugh Kang), who said:

>> >"0,5,10,15,20, -> 55 * * * *" However, this is too long.
>>

>> Check your man page to see if your version of cron and/or crontab supports
>> the */5 construct.
>>

>I am with SCO UnixWare 7.1.1. "*/5" doesn't work on our system. I've got
>"unexpected character found in line". I checked man crontab but it doesn't say
>anything about it clearly. Anyone else please?

Start typing. :)

Liam Cunningham

unread,
Apr 17, 2003, 9:38:05 AM4/17/03
to
On Wed, 16 Apr 2003 10:01:04 +0000, Hugh Kang wrote:

[snip]

> I am with SCO UnixWare 7.1.1. "*/5" doesn't work on our system. I've got
> "unexpected character found in line". I checked man crontab but it doesn't say
> anything about it clearly. Anyone else please?
>
> Thanks
> Hugh

No, UW does not support the */5 syntax. Why is the older method too long?
If you feel that it makes the crontab listing unreadable, break it up into
multiple lines:
0,10,20,30,40,50 * * * * CMD
5,15,25,35,45,55 * * * * CMD

--

If at first you don't succeed,
read the manual......

scriptOmatic

unread,
Apr 17, 2003, 1:38:18 PM4/17/03
to

Hugh,
You might try opensysmon which allows you to control the execution of
any
job, like cron. It gives a visual interface to what is happening. It
also
if full compatible with cron -- it will monitor cron jobs as well as
it's own
jobs.

--
http://ftp.opensysmon.com is a shell script archive site with an
open source system monitoring and network monitoring software package.
Many platforms are supplied already compiled.

Barrett Richardson

unread,
Apr 17, 2003, 4:29:40 PM4/17/03
to


Barry Margolin wrote:
> Hugh Kang <sk...@leaguedata.com> wrote:
>
> >I am with SCO UnixWare 7.1.1. "*/5" doesn't work on our system. I've got
> >"unexpected character found in line". I checked man crontab but it
doesn't say
> >anything about it clearly. Anyone else please?
>
> What can "anyone else" say? Either your system supports it or it doesn't.
> If it doesn't, you go back to the standard syntax that you already know.
>
> I suppose you could install the cron daemon from FreeBSD or Linux -- I
> expect they will work in most other flavors of Unix as well.

Or gcron if the extra numbers annoy him that much.

Barrett


0 new messages