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: