识别Linux上运行的哪个syslog守护进程的最佳方法是什么?

时间:2022-10-07 20:15:20

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)来识别哪个syslog守护进程正在运行。最好的方法是什么?由于我只考虑基于RHEL和rpm的除垢,Debian及其衍生物可以忽略。

3 个解决方案

#1


2  

To the best of my knowledge, syslog-ng and rsyslog (the default) are the only ones available on RHEL. You could either probe the process space, see which process currently holds /var/log/syslog open 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

#2


1  

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.

如果您使用的是单个发行版,那么可能有更优雅的检查方法。

#3


0  

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文件了。希望它能帮到你。

#1


2  

To the best of my knowledge, syslog-ng and rsyslog (the default) are the only ones available on RHEL. You could either probe the process space, see which process currently holds /var/log/syslog open 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

#2


1  

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.

如果您使用的是单个发行版,那么可能有更优雅的检查方法。

#3


0  

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文件了。希望它能帮到你。