【发布时间】:2011-01-27 06:02:23
【问题描述】:
我有某些关键的 bash 脚本被我无法控制的代码调用,而且我看不到它们的控制台输出。我想要完整跟踪这些脚本的作用,以供以后分析。为此,我想让每个脚本都进行自我跟踪。这是我目前正在做的事情:
#!/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...
有没有更好、更清洁的方法来做到这一点?
【问题讨论】: