如何在 Linux 上的 Bash 中检查系统日志?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6074362/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 00:56:16  来源:igfitidea点击:

How to check syslog in Bash on Linux?

linuxbashsyslog

提问by kern

In C we log this way:

在 C 中,我们以这种方式记录:

syslog( LOG_INFO, "proxying %s", url );

In Linux how can we check the log?

在Linux中我们如何查看日志?

采纳答案by NPE

How about less /var/log/syslog?

怎么样less /var/log/syslog

回答by Hackonteur

On Fedora 19, it looks like the answer is /var/log/messages. Although check /etc/rsyslog.confif it has been changed.

在 Fedora 19 上,答案似乎是/var/log/messages. 虽然检查/etc/rsyslog.conf它是否已更改。

回答by kshiteejm

tail -f /var/log/syslog | grep process_namewhere process_nameis the name of the process we are interested in

tail -f /var/log/syslog | grep process_nameprocess_name我们感兴趣的进程名称 在哪里

回答by kenorb

By default it's logged into system log at /var/log/syslog, so it can be read by:

默认情况下,它登录到系统日志中/var/log/syslog,因此可以通过以下方式读取:

tail -f /var/log/syslog

If the file doesn't exist, check /etc/syslog.confto see configuration file for syslogd. Note that the configuration file could be different, so check the running process if it's using different file:

如果该文件不存在,请检查/etc/syslog.conf以查看 syslogd 的配置文件。请注意,配置文件可能不同,因此请检查运行过程是否使用不同的文件:

# ps wuax | grep syslog
root      /sbin/syslogd -f /etc/syslog-knoppix.conf

Note: In some distributions (such as Knoppix) all logged messages could be sent into different terminal (e.g. /dev/tty12), so to access e.g. tty12try pressing Control+Alt+F12.

注意:在某些发行版(例如 Knoppix)中,所有记录的消息都可以发送到不同的终端(例如/dev/tty12),因此要访问例如tty12尝试按Control+ Alt+ F12

You can also use lsoftool to find out which log file the syslogdprocess is using, e.g.

您还可以使用lsof工具找出syslogd进程正在使用的日志文件,例如

sudo lsof -p $(pgrep syslog) | grep log$ 


To send the test message to syslogd in shell, you may try:

要将测试消息发送到 shell 中的 syslogd,您可以尝试:

echo test | logger


For troubleshooting use a trace tool (straceon Linux, dtrusson Unix), e.g.:

对于故障排除使用跟踪工具(strace在 Linux 上,dtruss在 Unix 上),例如:

sudo strace -fp $(cat /var/run/syslogd.pid)

回答by NiceTIP

on the Asus router it could be done via

在华硕路由器上可以通过

:/bin# busybox

there are also other commands related to.

还有其他相关的命令。

回答by nhnghia

A very cool util is journalctl.

一个非常酷的工具是journalctl.

For example, to show syslog to console: journalctl -t <syslog-ident>, where <syslog-ident>is identity you gave to function openlogto initialize syslog.

例如,要将 syslog 显示到 console: journalctl -t <syslog-ident><syslog-ident>您赋予openlog用于初始化 syslog 的函数的标识在哪里。

回答by Andy Carlson

If you like Vim, it has built-in syntax highlighting for the syslog file, e.g. it will highlight error messages in red.

如果您喜欢 Vim,它具有用于 syslog 文件的内置语法高亮显示,例如,它将以红色高亮显示错误消息。

vi +'syntax on' /var/log/syslog