gpt4 book ai didi

linux - 忽略linux脚本中的tee

转载 作者:太空宇宙 更新时间:2023-11-04 05:13:20 25 4
gpt4 key购买 nike

我在红帽机器上有一个 .sh 脚本:

{
statement 1
statement 2
statement 3
etc....
} 2>&1 | tee "logdir/logfile.log"

它会记录到控制台和日志文件 logfile.com 中。但是,语句 2 提供了大量输出,我希望将其从日志文件中排除,同时仍在控制台中显示输出。

有没有办法将特定语句从 tee 中排除到日志文件中?

编辑:对声明的一些澄清:

{
echo some information on the environment
echo some checks

rsync -rtpgov /some/folder/ some/other/folder

tar -xf some/other/tar/file.tar -C some/other/folder2
tar -xf some/other/tar/file.tar -C some/other/folder3
tar -xf some/other/tar/file.tar -C some/other/folder4
etc...

echo some finishing checks
} 2>&1 | tee "logdir/logfile.log"

我希望排除 rsync 写入 logfile.log,同时仍然在控制台中看到输出。

最佳答案

处理tee后,您能看到应该排除哪些行吗?

当您在处理语句 2 时才知道这一点时,看起来您需要更改每个语句。

rm "logdir/logfile.log"
{
echo 1 2>&1 | tee "logdir/logfile.log"
echo 2 2>&1
echo 3 2>&1 | tee -a "logdir/logfile.log"
} 2>&1
echo ===
echo "Contents File "logdir/logfile.log"
cat "logdir/logfile.log"

当语句 2 显示不同类型的输出时,您可以关注它

rm "logdir/logfile.log"
{
echo 1 useful
echo 2 debug
echo 3 this I want
} 2>&1 | tee >(grep -Ev "debug|trace|other garbage" > "logdir/logfile.log")
echo ===
echo "File "logdir/logfile.log":"
cat "logdir/logfile.log"

当您不知道语句 2 会说什么,但想要过滤此语句而不更改其他行时,您可以采取解决方法:

rm "logdir/logfile.log"
{
echo 1 useful
echo 2 debug | sed 's/^/FREEZE/'
echo 3 this I want
} 2>&1 | tee >(grep "^FREEZE" > "logdir/logfile.log") | sed 's/^FREEZE//'
echo ===
echo "File "logdir/logfile.log":"
cat "logdir/logfile.log"

关于linux - 忽略linux脚本中的tee,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52664606/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com