Right now I have the following:
# this function is meant for future script expansions
# its purpose is clear, i.e. to clean up some temp files
# now, it is doing nothing, just a special null command
cleanup_on_signal() { :; }
# define functions to handle signals
# treat them as errors with appropriate messages
# example calls:
# kill -15 this_script_name # POSIX, all shells compatible
# kill -TERM this_script_name # Bash and alike - newer shells
signal_handler_HUP() { cleanup_on_signal; print_error_and_exit "\\ntrap()" "Caught SIGHUP (1).\\n\\tClean-up finished.\\n\\tTerminating. Bye!"; }
signal_handler_INT() { cleanup_on_signal; print_error_and_exit "\\ntrap()" "Caught SIGINT (2).\\n\\tClean-up finished.\\n\\tTerminating. Bye!"; }
signal_handler_QUIT() { cleanup_on_signal; print_error_and_exit "\\ntrap()" "Caught SIGQUIT (3).\\n\\tClean-up finished.\\n\\tTerminating. Bye!"; }
signal_handler_ABRT() { cleanup_on_signal; print_error_and_exit "\\ntrap()" "Caught SIGABRT (6).\\n\\tClean-up finished.\\n\\tTerminating. Bye!"; }
signal_handler_TERM() { cleanup_on_signal; print_error_and_exit "\\ntrap()" "Caught SIGTERM (15).\\n\\tClean-up finished.\\n\\tTerminating. Bye!"; }
# use the above functions as signal handlers;
# note that the SIG* constants are undefined in POSIX,
# and numbers are to be used for the signals instead
trap 'signal_handler_HUP' 1; trap 'signal_handler_INT' 2; trap 'signal_handler_QUIT' 3; trap 'signal_handler_ABRT' 6; trap 'signal_handler_TERM' 15
I want the script to terminate tidily on shutdown, which right now it does.
But I opened one suggestion of a colleague to issue a question on CTRL+C instead of quitting to shell.
I don't want to turn off the machine, I don't do that often, anyway:
What signal is sent to running programs / scripts on shutdown?