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

Is there a command line tool that will simply evaluate a cron expression and return a bool response if it is supposed to be running right now? I'm looking for something I can use as a utility in another bash script. Something like so:

run_script=$(/tools/evaluate-cron-expression "02 4 * * *")
if [ "$run_script" -eq "1" ] # etc etc

I know, I know, I could just setup a real cron job, but I'm playing with the idea of wrapping all of my scheduled scripts inside of another script.

share|improve this question
This is actually very cool and I could make it work, except my production servers are limited to PHP 5.2 :( – Jake A. Smith Nov 7 '12 at 21:21
What is the specific problem you are trying to solve? – mdpc Nov 7 '12 at 21:29
I want to pass a cron expression to a script and, given the current time, determine whether or not it is a match. – Jake A. Smith Nov 7 '12 at 21:33
I guess that is pretty specific, but again why? What more general problem are you trying to solve that would lead you to a solution like this? – mdpc Nov 7 '12 at 21:35
So you are basically duplicating the cron function? Why not use the functionality contained putting the cron entries into seperate files under /etc/cron.d? – mdpc Nov 7 '12 at 22:15
up vote 0 down vote accepted

You can find a Class that deals with this here:

I've been using this Class for something like 7 years. It has worked flawlessly.

share|improve this answer
Thanks! Exactly what I wanted. – Jake A. Smith Nov 10 '12 at 17:19

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.