Better way to make a bash script self-tracing?
Posted
by Kevin Little
on Stack Overflow
See other posts from Stack Overflow
or by Kevin Little
Published on 2010-03-13T20:40:46Z
Indexed on
2010/03/13
20:45 UTC
Read the original article
Hit count: 276
I have certain critical bash scripts that are invoked by code I don't control, and where I can't see their console output. I want a complete trace of what these scripts did for later analysis. To do this I want to make each script self-tracing. Here is what I am currently doing:
#!/bin/bash
# if last arg is not '_worker_', relaunch with stdout and stderr
# redirected to my log file...
if [[ "$BASH_ARGV" != "_worker_" ]]; then
$0 "$@" _worker_ >>/some_log_file 2>&1 # add tee if console output wanted
exit $?
fi
# rest of script follows...
Is there a better, cleaner way to do this?
© Stack Overflow or respective owner