忽略linux脚本中的tee
我在red hat机器上有一个.sh脚本:忽略linux脚本中的tee,linux,unix,command,tee,Linux,Unix,Command,Tee,我在red hat机器上有一个.sh脚本: { statement 1 statement 2 statement 3 etc.... } 2>&1 | tee "logdir/logfile.log" 它同时登录到控制台和logfile logfile.com。然而,语句2给出了大量的输出,我希望将其从日志文件中排除,同时仍在控制台中显示输出 是否有方法将特定语句从tee排除到日志文件 编辑: 对声明进行一点澄清: { echo some information on the
{
statement 1
statement 2
statement 3
etc....
} 2>&1 | tee "logdir/logfile.log"
它同时登录到控制台和logfile 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"
我自己找到了一个简单可行的解决方案:
{
echo some information on the environment
echo some checks
# etc....
} 2>&1 | tee "logdir/logfile.log"
{
rsync -rtpgov /some/folder/ some/other/folder
} 2>&1 | tee "logdir/rsync.log"
{
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 -a "logdir/logfile.log"
由于要记录的语句数量相对较大,并且日志文件的输入变化很大,因此将日志文件拆分为2似乎更方便。
使用-a选项,日志行将被附加到日志文件中您能在语句之前显示更多的代码吗?你能在if(语句2)之前加一个条件吗?或者这些语句只存在于你的函数中吗?