40m QIL Cryo_Lab CTN SUS_Lab TCS_Lab OMC_Lab CRIME_Lab FEA ENG_Labs OptContFac Mariner WBEEShop
  40m Log  Not logged in ELOG logo
Entry  Wed May 30 15:51:22 2012, yuta, Update, IOO, MC beam spot oscillation specMC3_onoff_localdamping.pdf
    Reply  Wed May 30 19:27:38 2012, yuta, Update, IOO, MC beam spot oscillation 
       Reply  Wed May 30 20:12:15 2012, rana, Update, IOO, MC beam spot oscillation 
          Reply  Thu May 31 10:31:19 2012, Jamie, Update, IOO, MC beam spot oscillation 
Message ID: 6728     Entry time: Thu May 31 10:31:19 2012     In reply to: 6719
Author: Jamie 
Type: Update 
Category: IOO 
Subject: MC beam spot oscillation 

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
...
ELOG V3.1.3-