Add clean_up function. Trap signals SIGHUP SIGINT SIGTERM

This commit is contained in:
Christoph 2017-06-28 01:15:07 +02:00
parent 24ba503a6f
commit b3761600fa

View File

@ -27,14 +27,20 @@ LOCK_DIR=`mktemp -d`
#----------------------------- #-----------------------------
#--------------------------------------- #---------------------------------------
clean_up() {
# Perform program exit housekeeping
rm rf $LOCK_DIR
exit $1
}
fatal(){ fatal(){
echo "" echo ""
echo -e " [ Fatal ] $*" echo -e " [ Fatal ] $*"
echo "" echo ""
echo -e "\tScript terminated.." echo -e "\tScript terminated.."
echo "" echo ""
rm -rf $LOCK_DIR clean_up 1
exit 1
} }
error (){ error (){
@ -68,6 +74,10 @@ trim() {
echo -n "$var" echo -n "$var"
} }
# - The trap command allows you to execute a command when a signal
# - is received by your script.
# -
trap clean_up SIGHUP SIGINT SIGTERM
#--------------------------------------- #---------------------------------------
#----------------------------- #-----------------------------