bash 识别 Linux 上运行的系统日志守护程序的最佳方法是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12510829/
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
What is the best way to identify which syslog daemon is running on Linux?
提问by mwak
I'm writing Linux shell script (sh, bash or csh) to identify which syslog daemon is running. What is the best way to do it? Since I only consider RHEL and rpm based destribution, Debian and its derivatives can be ignored.
我正在编写 Linux shell 脚本(sh、bash 或 csh)来识别正在运行的系统日志守护程序。最好的方法是什么?由于我只考虑基于 RHEL 和 rpm 的分发,因此可以忽略 Debian 及其衍生产品。
采纳答案by gvalkov
To the best of my knowledge, syslog-ngand rsyslog(the default) are the only ones available on RHEL. You could either probe the process space, see which process currently holds /var/log/syslogopen or simply check which syslog daemon is installed (though, it's possible to have them both installed at the same time).
据我所知,syslog-ng和rsyslog(默认)是 RHEL 上唯一可用的。您可以探测进程空间,查看当前哪个进程保持/var/log/syslog打开状态,或者只是检查安装了哪个 syslog 守护进程(不过,可以同时安装它们)。
$ lsof /var/log/messages /var/log/syslog 2>&1 | grep syslog
$ rpm -q rsyslog syslog-ng
$ pgrep -u root syslog | xargs ps -p
回答by Tim Lamballais
One could parse the output of lsof to see which processes have the file /var/log/syslog open, a very crude example would be:
可以解析 lsof 的输出以查看哪些进程打开了文件 /var/log/syslog,一个非常粗略的例子是:
sudo lsof | grep /var/log/syslog | cut -f1 -d' '
If you are using a single distribution there may be more elegant ways of checking.
如果您使用的是单一发行版,则可能有更优雅的检查方式。
回答by Matt Setter
On a debian-based system, run the following script to see what's installed:
在基于 debian 的系统上,运行以下脚本以查看安装的内容:
dpkg-query -l '*syslog*' | grep ii
This will give you output similar to the following
这将为您提供类似于以下内容的输出
ii rsyslog 7.4.4-1ubuntu2.3 i386 reliable system and kernel logging daemon
That way you don't have to grep files etc. Hope it helps you out.
这样你就不必 grep 文件等。希望它可以帮助你。

