我有一些關鍵的bash腳本,這些腳本是由我不控制的代碼調用的,而且我無法看到他們的控制檯輸出。我想要了解這些腳本爲以後的分析做了些什麼。要做到這一點,我想讓每個腳本自我追蹤。這是我目前正在做的:更好的方法來使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 "[email protected]" _worker_ >>/some_log_file 2>&1 # add tee if console output wanted
exit $?
fi
# rest of script follows...
有沒有更好,更乾淨的方法來做到這一點?
最優秀!我只知道必須有更優雅的方式。謝謝,凱文;這將立即使用... – 2010-03-13 23:46:12
它也可以輸出到當前終端並登錄到文件?我試圖用'exec'使用'tee',但是沒有發現任何方法.. – 2013-10-30 16:08:22
我想鏈接到[這個問題](http://stackoverflow.com/questions/3173131/redirect-copy-of-stdout-to -log-file-from-within-bash-script-its)在哪裏可以看到輸出並記錄下來,所有命令都來自腳本內部! – 2013-10-30 16:30:18