Specifications

You need to use the chmod tool to indicate to the operating system that the text le
is executable (that is, its contents can be run as a program). To make a shell script
executable:
chmod 755 YourScriptName.sh
After making the shell script executable, you can run it by entering its pathname.
For example:
~/Documents/Dev/YourScriptName.sh
or
cd ~/Documents/Dev/
./YourScriptName.sh
For more information about using chmod, see its man page. For more information
about running your shell scripts, see “Executing Commands and Running Tools
on page 13 .
Monitoring and Restarting Critical Services with launchd
Mac OS X includes a system for monitoring and running critical service, which you
may want to use to run various shell scripts. This system is uses a daemon named
launchd. During system startup, launchd is the rst process the kernel runs to set
up the computer. In Mac OS X Server, your daemon should be started by launchd.
Other mechanisms for starting daemons and services are subject to removal at
Apples discretion.
You can get an idea of the various processes run by launchd by looking at the
following conguration les:
Folder Usage
/System/Library/LaunchDaemons/ Apple-supplied system daemons
/System/Library/LaunchAgents/ Apple-supplied agents that apply to all users on
a per-user basis
/Library/LaunchDaemons/ Third-party system daemons
/Library/LaunchAgents/ Third-party agents that apply to all users on
a per-user basis
~/Library/LaunchAgents/ Third-party agents that apply to the logged-in
user only
You do not interact with launchd directly—instead you use launchctl to load or
unload launchd daemons and agents.
24 Chapter 3 Scripting the Command Line