There is often a need to debug scripts which are started by daemons, so you have no input/output available. The following snippet easily redirects stdout and stderr to a file:
#!/bin/bash exec >> /tmp/script_debug.log 2>&1 set -x echo Start: $(date) : buggy code echo Stop: $(date)
and here the output:
$ cat /tmp/script_debug.log ++ date + echo Start: Sat Dec 15 08:37:45 CET 2012 Start: Sat Dec 15 08:37:45 CET 2012 + your-buggy-cmd foo: line 8: your-buggy-cmd: command not found ++ date + echo Stop: Sat Dec 15 08:37:45 CET 2012 Stop: Sat Dec 15 08:37:45 CET 2012
Comments are closed, but trackbacks and pingbacks are open.