我正在尋找一個解決方案(類似於下面的bash代碼)將stdout和stderr複製到除了ksh在Solaris中的屏幕之外的文件。將stderr和stdout複製到文件以及ksh中的屏幕
下面的代碼在bash shell中的偉大工程:
#!/usr/bin/bash
# Clear the logfile
>logfile.txt
# Redirect all script output to a logfile as well as their normal locations
exec > >(tee -a logfile.txt)
exec 2> >(tee -a logfile.txt >&2)
date
ls -l /non-existent/path
出於某種原因,這是扔在Solaris語法錯誤。我認爲這是因爲我不能進行流程替換,並且我看到一些帖子提示使用mkfifo
,但我還沒有想出一個可行的解決方案。
有誰知道一種方式,除了默認位置之外,所有輸出都可以重定向到文件嗎?
這幾乎是我所需要的,但是這不會將STDOUT和STDERR文件描述符分開。如果我像'./script.sh> out.log 2> err.log'那樣調用腳本,那麼所有的輸出都會輸出到out.log,但是有些應該到err.log – HuggieRich
好,所以你需要另一個'tee '和管道 - 修改原來的答案... – cdarke
它排序,非常好。 – HuggieRich