Bash – Evaluate cron expression

bashcron

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.

Best Answer

You can find a Class that deals with this here: http://www.phpclasses.org/package/641-PHP-Compares-timestamps-with-crontab-style-specifiers.html

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