Question

I have a script that I want to execute daily, which requires an Internet connection in order to properly execute. However, my laptop (where the script resides) is not always on, and is not always connected to the Internet.

I want the script to execute at, say, 8:00am every day. However, if the computer is off or not connected to the Internet at 8:00, I want the script to execute at the next available chance.

How can I achieve this using cron, launchd or some other manager? Bonus points if the answer avoids having to fail the job every, say, 5 seconds once the computer turns back on, and until I connect to the Internet and it properly executes.

If it matters, I'm running OSX Mountain Lion.

Was it helpful?

Solution

anacron is probably your answer. It's usually installed on linuxes but is optional, and can be left off if your system administrator decided not to include it. On OS/X, it's a little more challenging, but there are pages on the internet explaining it better than I have room to here. Anacron running from launchd can be done.

On linux the man page should point you in the right direction.

Additionally you can make your script aware of the internet connection with a wget command and interrogate the results. If it's unsuccessful, go into a loop waiting for an internet connection to work with a timer of 10 minutes or whatever makes sense to you.

Hit me up if you need details of how to accomplish any of these tasks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top