shell scripting best practices - trap command

I know there is a command called

trap

which can be used to capture the signals from a shell script and redirect the control to a required function (such as a cleanup).

My question is - Those of you who have written lot of shell scripts - do you always write a set of trap commands to capture the most frequently occuring abnormal signals and handle them in script manually? Is it a best practice kinda thing to use trap command in a shell cript?

For my part I do use the trap command very rarely. If I have need for it, I do but usually I don't since the scripts I write are for admin purposes etc. and they run mostly as root or with an technical account so I don't have to fear any unwanted kills interrupting them.

There are 2 signals that I trap in almost every script: SIGUSR1 and 0. I use SIGUSR1 in long-running scripts to print a short status message instead of constantly cluttering the screen, an 0 (a shell-builtin signal meaning EOF) to collect all clean-up stuff in one function, instead of having to worry about it at every possible exit.

Is there a signal that is triggered if the script exits due to the lack of disk space?

S

I use it to exit foreground monitoring scripts which have a "while true" loop and some background tasks which need killing occasionally. Doubt if it will catch "out of disc space" even when the shell itself is writing to disc.
The main use is to action "ctrl/c" from the command line in a controlled manner.

Avoid calling the exit routine "EXIT" because it is an undocumented reserved word.

#!/bin/ksh
MYEXIT()
{
## Cleanups go here
exit
}

trap 'MYEXIT' 1 2 3 15

### processing


## last line dropthrough
MYEXIT