如何在 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
How to check syslog in Bash on Linux?
提问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.conf
if it has been changed.
在 Fedora 19 上,答案似乎是/var/log/messages
. 虽然检查/etc/rsyslog.conf
它是否已更改。
回答by kshiteejm
tail -f /var/log/syslog | grep process_name
where process_name
is the name of the process we are interested in
tail -f /var/log/syslog | grep process_name
process_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.conf
to 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. tty12
try pressing Control+Alt+F12.
注意:在某些发行版(例如 Knoppix)中,所有记录的消息都可以发送到不同的终端(例如/dev/tty12
),因此要访问例如tty12
尝试按Control+ Alt+ F12。
You can also use lsof
tool to find out which log file the syslogd
process 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 (strace
on Linux, dtruss
on 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 openlog
to 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