Context: I want to schedule various servers I look after to install various updates (both through SU and not) and restart as and when necessary but remotely and out of office hours. Not on a regular basis (daily/weekly/monthly etc) but as and when we're sure the update isn't going to break stuff...

My question is a little more general than that: how should I schedule one off jobs like this? Presumably more than one way of going about it, interested to hear what people think, whether it's scripting it or 3rd party utilities, whatever.

  • Are you running these commands from a local machine, or do you want the servers themselves to handle this? – jmlumpkin Feb 14 '12 at 14:56
  • @jmlumpkin it depends although it would probably be rare for the command to come from a local machine. I'm interested in all suggestions though! It's a general 'good practice' question. – Robin Feb 14 '12 at 18:45

There are 3 options I can think of, all of which rely on your setup/tools you have. For this, I am also assuming you are working with Mac servers.

  1. Apple Remote Desktop and Scheduled Tasks
  2. iCal and alarms
  3. the bash 'at' command.

Apple Remote Desktop

ARD will allow you to run tasks on remote machines, and they can be either done instantly or at a scheduled future time. You could create your task that you need to run, click on the machine you want to run it on, select the task, then schedule it for when needed. This queues up the task for that time. More details on how to use ARD to do this are available on Apple's website under RemoteDesktop 3.0 help. I no longer have ARD to verify, but I think the remote task is queued on that machine, and therefore ARD does not need to be running on your machine to run the update.

iCal and Alarms

iCal will allow you to add an event that can execute a script at a defined time.

You do this by adding an event in iCal, and where the Alarm option is for the event, you can select Run Script, and then pull up the AppleScript you would like to run.

There are pitfalls with this. The local computer you are on (that had iCal) would need to be able to connect to the remote machine, and most likely be awake (I have not tested if this will wake the machine to run). This is also much less reliable than the ARD or 'at' option (I assume this was made for users to simply automate something on their machine, versus a sysadmin tool).

The 'at' command

The bash 'at' command will allow you to run a task at a specified time. You will need to make a bash shell script for your task, and then save it, as well as set the correct execution/permission settings. Once that is done, you can use the 'at' command to schedule it, using something like:

at -f updatesoftware.sh -v 10:30

The script should then execute and send you feedback if mail is set up correctly. According to this site, you need to make sure you enable 'at' on the Mac though, using the following command:

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.atrun.plist

I would review the man page (using man at) to determine the exact configuration you prefer. Using this option though, you can schedule the task on the particular machine you want to run on, therefore taking extra machines (like the previous two examples) out of the equation.

| improve this answer | |

I'd probably use a combination of a bash script and the 'at' command; if your tasks are generic enough you could build a small library of task scripts to pull from when you needed to run a job.

| improve this answer | |

You must log in to answer this question.

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