BASH scripting lesson 8 using TRAP to control scripts
More videos like this online at www.theurbanpenguin.com
Now we really have some fun with our scripts adding in TRAP to help make the scripts more robust. We may need our script to exit correctly each time. We can do this by creating a PID file and checking for its existence. If it does exist then the script did not exit cleanly last time. we also then must make sure we provide a method to delete the file as we exit. Scripts normally do not respond to terminate signals sent from kill, but we too can eable this with traps to make sure we listen to calls from the system, I am sure this will help with your scripts and you will want to implement these ideas in some of your projects.