bash + 如何避免日志文件中的特定消息

bash + how to avoid specific messages in the log file

当我在我的 Linux 机器上 运行 bash 脚本时,我的日志中出现以下错误,

注意 - 我们在脚本中设置:

exec > $log 2>&1 ,  (  in order to send all standard error/output to $log ) 

错误消息:

tput: No value for $TERM and no -T specified

为了过滤此错误消息,我们尝试在 bash 脚本中设置:

export TERM=xterm

但没有帮助

在挖掘之后我们发现在某些情况下会发生这种情况,例如当我们通过 ssh 对远程机器执行 ssh 和 运行s 命令时

为了避免我们在 bash 脚本中设置 TERM=xterm 如下:

ssh user@$remote_machine "TERM=xterm  /tmp/script.sh"

但这不是一个很好的解决方案,因为我的脚本使用了很多 ssh 和 curl 命令,所以在每个 SSH 或 curl 等上设置它不是实用的解决方案

所以我的大问题是

如何过滤消息 – tput: $TERM 没有值并且没有指定 -T ?

所以我们不会在我的 $log 文件

中收到这些难看的消息

从日志记录中过滤掉所有 tput: No value

exec > >(grep -v 'tput: No value for $TERM and no -T specified' >$log) 2>&1