1833301 Members
2946 Online
110051 Solutions
New Discussion

crontab */2 for HP-UX

 
SOLVED
Go to solution
Anna Fong
Advisor

crontab */2 for HP-UX

Hi,

Came across a reference in the ITRC forums to using */2 notation to schedule crontab for ever other minute. Tested in Linux and FreeBSD and works. Doesn't work in HP-UX or Solaris. Any reason why? How about a workaround?

*/2 * * * * echo `date` > junk
crontab: error on previous line; unexpected character found in line.
5 REPLIES 5
Patrick Wallek
Honored Contributor
Solution

Re: crontab */2 for HP-UX

That doesn't work because it is non-standard notation for cron.

For HP-UX and solaris, and to keep everything straight, I prefer the standard cron format:

0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * /path/to/job

That was there is no question as to when the job will run.

Another workaround:

# cat /path/to/job

#!/usr/bin/sh
....
stuff to do
....
at -f /path/to/job now + 2 minutes


The at statement will reschedule the job every 2 minutes.
Shannon Petry
Honored Contributor

Re: crontab */2 for HP-UX

Linux does alot of non-standards things, which I for one really do not like.

In actuality
*/2 should be every 30 seconds as it would be a minute divided by 2. But.. Someone elses logic dictated this change for their needs, some people thought it was cool so it was implemented in the gpl versions of cron.

A rule of thumb I have is to use standards. I write all scripts so that they port to any OS. I use my own wrappers for every script to handle path differences, but command syntax is globally accepted.

That being said, I'll warn you that I support HP, Sun, Irix, AIX, SCO, and Linux. It takes some getting used to to be able to do 1 job and have it be done on all of these variants, but it's definatly do-able and worth the efforts.

If you really need something to run every-other minute, then write it long hand as someone else mentioned. It's not a standard, and I dont forsee it being one any time soon.

Regards,
Shannon

Microsoft. When do you want a virus today?
Anna Fong
Advisor

Re: crontab */2 for HP-UX

Patrick,

Yes, was looking for shorthand for standard notation but guess there isn't if I'm sticking with standard cron.
Anna Fong
Advisor

Re: crontab */2 for HP-UX

Shannon,

Yes, would make more sense to do something like *%2
dan dobbs
Frequent Advisor

Re: crontab */2 for HP-UX

You got off light. I had the same question a week ago, but took a heap of abuse from the old timers. (see

[Broken link removed on <4/18/2017> by Mod]
. :>)

Short answer, HP-UX cron seems to stick with the most compatible (and documented)parameters, and the Linux flavor doesn't.

Best of luck,

-dd

Hey, that's not a spoon.