Quote: |
This is a common occurrence when diagnostic scripts are written without the ability to handle exceptions (e.g. ctrl-c, terminal gets closed, etc.).
The first thing to do is make sure that the "new" script you are writing doesn't already exist (hint: look in the old scripts directory).
If you are writing a script that touches things in the interferometer, it must always return the settings to the initial state on abnormal termination:
http://linuxdevcenter.com/pub/a/linux/lpt/44_12.html
|
This is very good advice. However, "trap" is bash-specific. tcsh has a different method that uses a function called "onint". Here's a description of the difference.
A couple notes about bash traps:
- You can give a name instead of a number for the signal. So instead of
trap 'do stuff' 1 you can say trap 'do stuff' SIGHUP
- The easiest signal to use is EXIT, which covers all your bases (ie. anything that would cause the script to exit prematurely.
- You can define a function that gets executed in the trap
So the easiest way to use it is something like the following:
#!/bin/bash # define cleanup function function cleanup { # do cleanup stuff, like reset EPICS records to defaults .... } # set the trap on EXIT trap cleanup EXIT # the rest of your script below here
...
|