2

I am trying to run a script through crontab in osx 10.8.5 that will run at 4:30.

30 16 * * 1-5 /Library/Frameworks/Python.framework/Versions/2.7/bin/python /Users/lego90511/PycharmProjects/Stock\ Scanner/stock_scanner.py

But I realized today that, my computer is not always on at 4:30. So I added the fix * 16 * * 1-5. But then I realized it may not be at all between 4-5. How can I set crontab to run anytime after 4pm(16 cron time)?

2 Answers 2

4

Due to the way cron does its processing, I'm not sure you can use cron by iteself to do this. From the cron(8) man page:

The cron utility then wakes up every minute, examining all stored crontabs, checking each command to see if it should be run in the current minute. When executing commands, any output is mailed to the owner of the crontab (or to the user named in the MAILTO environment variable in the crontab, if such exists).

Cron has no method to identify entries it has already run. So, you could conceivably do this:

* 16-23 * * 1-5 <script>

But, that would just tell cron to run this script every minute from 16:00 to 23:59, as long as cron was running. (Looking at the crontab(5) man page, I don't think you can do "16-24" or "16-0.")

So, if you wanted something to run once between 4pm and midnight, my suggestion would be to have cron launch the script every 15 minutes, after 4pm:

*/4 16-23 * * 1-5 <script>

Then, within the script, include some method to identify if the script has already been run that day.

1

For Linux there is Anacron for missed cron-jobs. (see here)

For Mac OSX i found this version but it seems to be discontinued.

There is also a version here which is for "Leopard":

Note: This version of Anacron will run on MacOS 10.5 (Leopard) but it is not needed, as the Leopard launchd will run skipped jobs when the machine is next awake. Read more at http://mac.majorgeeks.com/files/details/anacron.html#Z5s7GokjQVbUATOU.99

You could try if it runs on "Mountain lion" or switch to "Launchd" which has the functionality to run missed jobs built in.


Cron and Anacron
If you run Mandrake, SUSE, or any other distros and your computer is not powered up 24 hours a day, there are several Cron jobs that might be forgotten because they're scheduled for 3:00AM-4:00AM in the morning. Installing Anacron will set this to rights. Anacron searches for missed Cron jobs and executes them five minutes after you boot your computer. You'll notice extra activity of your CPU and hard disk for about five to seven 7 minutes as a result. Note: Red Hat and Fedora have Anacron pre-installed by default.

Installing Anacron is simple and needs no special configuration. Here's an example of how to install it using Mandrake:

Mandrake Control Center > Software Management > Installing Software > search for Anacron.

You must log in to answer this question.

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