Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i need to make a cron job to run a java program every 40 minutes on unix server. considering that: 1)it should run from 8h30 to 12h30 and from 14h to 18h from monday to friday 2) take consideration of holidays.

i've read a lot about it and found this */30 8..13,14..19 * * 1..5 as the closest solution. i wanna know if crontab can do what i want, and if not is it possible to right a java or whatever code to verify the holiday date. thanks for your help

share|improve this question
up vote 0 down vote accepted

CRON isn't that clever, you will either need to have lots of similar rules, or write something a little more bespoke to do it for you (but be careful, you don't want to write a script that runs user provided stuff as root without taking special care. Scratch that, you don't want to write a script that does that full stop)

share|improve this answer

Like James said, cron isn't really that smart: It's good at "Do these things at these times, over and over again until I tell you to stop", but it's not going to follow floating holidays or be thrilled about "funky" timings like every 40 minutes (It requires a bunch of crontab entries to do something like that - you pretty much need to make one for each run).

You are probably best off getting "as close as practical" with cron (i.e. your rule above, which is "Run every half hour on the HH:30 mark" within the restrictions of part 1), and then having your script check for the exceptions (holidays) on its own and decide if it should/shouldn't proceed.

share|improve this answer

It may be overkill for what you want, but you could use Hudson to run the jobs. In itself you won't immediately get the ability to run the jobs using your timing rules, but you can trigger jobs remotely by any number of methods. So if you can write a script to change the content of a webpage or create new files or do a REST call to Hudson or do a git checkin whenever you want the job running then you're in luck. You also gain better logging than cron alone, and it's easy to get alerted whenever the job fails (by email, jabber, irc, nabaztag...)

Looking at this from another perspective. Do you really need it to run within the specified rules? What happens if you run it every half hour instead? What happens if you run it at times you don't want?

share|improve this answer
well my java program insert data from a csv file to a database on a linux server. while the csv file itself is created by a vba program running on a windows machine that update it every 30 min. i need those rules to prevent the acces of both programs to the file at the same time. – daria Aug 10 '10 at 17:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.