如何过滤 Ubunty 系统日志文件中的错误?

如何过滤 Ubunty 系统日志文件中的错误?

如何在 Ubunty 系统日志文件中查找错误,特别是可能导致各种问题并证明系统已损坏的错误,而不是小的任意错误。我的意思是在日志文件中搜索包含错误、损坏、失败、崩溃消息的行。哪些日志文件最重要?我安装了格洛格日志探索实用程序。是否有方法可以扫描多个日志文件并过滤出重要的错误消息以将其保存到单独的文件中以供分析?

答案1

最简单的方法是grep在终端窗口中使用。您应该首先检查的日志文件是syslog。因此,输入:

grep -i -e fail -e error -e corrupt /var/log/syslog

会显示包含您输入的关键词的所有行-e开关。-我开关指示grep忽略大小写。

答案2

现在在 Ubuntu 系统上日志,你实际上可以根据优先级过滤所有日志元数据,而不是寻找可能(或不可能)的文本字符串意味着优先级。

用于journalctl显示日志。它有很多过滤选项,但查找错误的选项是这个:

-p, --priority=
           Filter output by message priorities or priority ranges. Takes either a single numeric or textual log level (i.e. between
           0/"emerg" and 7/"debug"), or a range of numeric/text log levels in the form FROM..TO. The log levels are the usual syslog
           log levels as documented in syslog(3), i.e.  "emerg" (0), "alert" (1), "crit" (2), "err" (3), "warning" (4), "notice" (5),
           "info" (6), "debug" (7). If a single log level is specified, all messages with this log level or a lower (hence more
           important) log level are shown. If a range is specified, all messages within the range are shown, including both the start
           and the end value of the range. This will add "PRIORITY=" matches for the specified priorities.

因此,如果您想在所有日志中搜索被归类为“紧急”、“警报”、“严重”或“错误”(这是最严重的 4 个级别)的内容,那么使用:

journalctl -p 0..3

答案3

最简单的方法是在终端窗口中使用 grep。您应该首先检查的日志文件是Syslog。因此,输入:

grep -i -e fail -e error -e corrupt /var/log/syslog

相关内容