
226
|
Chapter 9, Administration and Automation
#73 Don’t Let Elvis Leave the Building
HACK
#!/bin/bash
# start up xcompmanager with drop shadows and fade effects
instances=`ps ax | grep "xcompmgr -cCfF" | grep -v grep | wc -l`
if [ $instances == 0 ]; then
while true; do xcompmgr -cCfF -l 0 -t 0 -r 5 -o .6 ; done
else
exit 1
fi
The first thing the script does is check to see if the command is already run-
ning. If so, the script exits. Perhaps you forgot you already started this
script, or perhaps you started the command manually. In either case, you
don’t want to start two instances, and this portion of the script prevents
that.
Notice that the
xcompmgr command is not followed with an ampersand. That
would launch xcompmgr in the background and return control to the script.
Then the script would proceed to try to launch more instances of xcompmgr
over and over again. Trust me. That’s a bad thing.
Now save your work and make this script executable with this command:
# chmod +x /usr/local/bin/keep-xcompmgr-running
The script is a simple infinite loop. But it doesn’t just start new instances of
xcompmgr over and over again. The xcompmgr program does not return
control to the script unless it fails, so this script will get to the point where it
launches the
xcompmgr command and its arguments, and then stop running.
If xcompmgr encounters a bug that causes it to exit unexpectedly, control
returns automatically