Debugging shell scripts comes handy, especially when unexpected things happen. Trust me, they do. I use two different approaches, based on what’s needed: debug while running it or when ran in the background, maybe by cron.
- Instead of ./script.sh run
sh -x script.shor
bash -x script.sh
- When the script is invoked by cron things are slightly different, though still simple:
set -xto your script, after
- keep an eye on
PS: The bash reference manual has many useful information