How do I have a script run every, say 30 minutes? I assume there are different ways for different OSs. I'm using OS X.
You can use the cron scheduler built into OS X. Here's a primer.
On MacOSX, you have at least the following options:
From personal experience, cron is the most reliable. When I tested, launchd had a number of bugs and quirks. iCal alarms only run when you are logged in (but that might be something you prefer).
Don't use cron as people have suggested. cron is legacy on OS X. Use launchd instead. It's different if you need to run it as system task (for all users) or as user task, just when your user is logged.
System tasks go to
/Library/LaunchDaemons/
if they shall run, no matter if any user is logged in at all. If they shall only run if any user is logged in, they go to
/Library/LaunchAgents/
if they shall run only if you are logged in, they go to
~/Library/LaunchAgents/
where ~ is your HOME directory.
Every task there is a file in plist format. It should have reverse domain name notation. E.g. you can name your task
com.example.my-fancy-task.plist
This plist can have various options and settings. Writing one per hand is suboptimal, you may want to get the free tool Lignon to create your task.
Just as an example, it could look like this
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.example.my-fancy-task</string>
<key>OnDemand</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>/usr/local/bin/my-script.sh</string>
</array>
<key>StartInterval</key>
<integer>1800</integer>
</dict>
</plist>
This agent will run the shell script /usr/local/bin/my-script.sh every 1800 seconds (every 30 minutes). You can also have task run on certain dates/times (basically launchd can do everything cron can do) or you can even disable "OnDemand" causing launchd to keep the process permanently running (if it quits or crashes, launchd will immediately restart it). You can even limit how much resources a process may use (as said before, Ligon shows all these settings in a nice UI interface).
Also you can manually enable/disable tasks via command line:
launchctl <command> <parameter>
command can be load or unload, to load a plist or unload it again, in which case parameter is the path to the file. Or command can be start or stop, to just start or stop such a task, in which case parameter is the label (com.example.my-fancy-task).
For apple scripts, I set up a special iCal calendar and use alarms to run them periodically. For command line tools, I use launchd.
As Mecki pointed out, launchd would be the way to go with this. There's a GUI interface for launchd called Lingon that you might want to check out, as opposed to editing the launchd files by hand:
Lingon is a graphical user interface for creating an editing launchd configuration files for Mac OS X Leopard 10.5.
[snip...]
Editing a configuration file is easier than ever in this version and it has two different modes. Basic Mode which has the most common settings readily available in a very simple interface and Expert Mode where you can add all settings either directly in the text or insert them through a menu.
Some screenshots are available to to give you an idea of what it looks like: