At top of your bash script add this after `#!/bin/bash` line to aborts the script immediately and add robustness to your script
```
set -euo pipefail
```

Use the following to trap error and show line number where your script failed to debut at run time or development time:
```
_failed() {
echo "$0 - Script failed at line $1"
}

# Trap the ERR
trap '_failed $LINENO' ERR
```

See `man bash` or `help set` for more.

@nixCraft for stuff that runs in a cronjob, I like to take this even further. Every operation redirects its stdout to a log file, and the trap cats that log into an email (usually local postfix/opensmtpd) to root. I like to also include some system info (w, uptime, free) for a bit more context. It’s really cool what you can do with simple built in unixey tools!