【发布时间】:2014-02-17 13:03:44
【问题描述】:
在我的 bash 脚本中,我在不同的日志中使用 grep,如下所示:
LOGS1=$(grep -E -i 'err|warn' /opt/backup/exports.log /opt/backup/imports.log && grep "tar:" /opt/backup/h2_backups.log /opt/backup/st_backups.log)
if [ -n "$LOGS1" ] ]; then
COLOUR="yellow"
MESSAGE="Logs contain warnings. Backups may be incomplete. Invetigate these warnings:\n$LOGS"
我不想检查每个日志是否存在(还有比这更多的日志),我想在脚本运行时检查 stderr 以查看是否得到任何输出。 如果其中一个日志不存在,则会产生如下错误: grep: /opt/backup/st_backups.log: No such file or directory
我尝试使用 command 2> >(grep "file" >&2 之类的命令读取 sterr,但这似乎不起作用。
我知道我可以将输出通过管道传输到文件,但我宁愿在有任何输出时处理 stderr 而不是读取文件。或者有什么理由为什么管道到文件更好?
【问题讨论】: