4

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?

4
  • cron is not that advanced when it comes to scheduling tasks. What you are trying to accomplish is a job for advanced task schedulers, likes of Tivoli Maestro et al. Using cron, the best way is to run your job on days 0,4,5,6 and at the script entry point, perform a logic check regarding the day of the week and time of day to determine if you are in the "run" period. If not, just exit.
    – MelBurslan
    Jan 13, 2015 at 20:34
  • @MelBurslan Yeah, that's my initial thoughts (the ability isn't there), but it's amazing the "magic" that can be done by "linux wizards" and little known functionality and tricks. I'm leaning towards that solution (Run on those days, exit if outside time range) but was just throwing feeler out there incase there was something I missed.
    – WernerCD
    Jan 14, 2015 at 14:45
  • 1
    I'd schedule it 17-23 Fri, 0-23 Sat+Sun, 0-5 Mon.
    – Barmar
    Jan 14, 2015 at 20:45
  • @Barmar For ease of implementation that's probably what I'm going to do since I think that is easier on the eyes than whats posted here.. that or, since we are talking about cygwin, utilize Windows Scheduler.
    – WernerCD
    Jan 15, 2015 at 19:34

1 Answer 1

0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .