How to schedule a cron task to run

croncygwin;scripting

I'm looking to crontab a script every hour starting Friday at 5pm… ending Monday at 5am.

This script checks if it's completed this week and if it's currently running. If no/no, start task.

Off the top of my head, I know I could do:

#Mins  Hours  DoMonth Months  DoWeek
0      5-17   *       *       0,6     /bin/echo "Run Script Sat and Sun Days"
0      17-24  *       *       0,5,6   /bin/echo "Run Script Fri, Sat, Sun Nights"
0      0-5    *       *       6,0,1   /bin/echo "Run Script Sat, Sun, Mon Mornings"

All the ways I can think involve three parts (Friday night, Sat/Sun all day, Monday Morning).

Is there a more efficient way to do this? Any kind of one/two-liner that would do this hourly, over that time frame?

Or would a simple check inside the script for this time frame (and exit if not in that time frame) be easier?

Best Answer

If you just want to check to see if the script is currently running, and if not, run it every hour, you could just do something like:

pgrep -x script-name.sh || script-name.sh

But you wouldn't want to do this unless you used a unique name for your script--don't use it with "echo" as your example above.

Related Question