How should I schedule a one off job?

Solution 1:

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.

Solution 2:

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.