大网数据广告活动
服务器运维问答

How to filter journalctl output by process name?

· 52CE 我爱测

When a process logs to systemd, its process name is recorded and displayed as identifier in the journalctl output. $ systemd-cat echo "test" $ journalctl -f -- Logs begin at Sat 2018-02-24 12:13:24 CET. -- ... Jul 25 13:52:26 myc…

问题原文

原帖链接 · Merlijn Sebrechts · CC BY-SA 4.0

When a process logs to systemd, its process name is recorded and displayed as identifier in the journalctl output.

$ systemd-cat echo "test"
$ journalctl -f
-- Logs begin at Sat 2018-02-24 12:13:24 CET. --
...
Jul 25 13:52:26 mycomputer echo[25098]: test

Filtering on that name, however, doesn't seem to work.

$ journalctl -f -t echo
-- Logs begin at Sat 2018-02-24 12:13:24 CET. --
$ journalctl -f -u echo
-- Logs begin at Sat 2018-02-24 12:13:24 CET. --

When I manually specify an identifier, the identifier is shown instead of the process name and filtering works.

$ systemd-cat -t myapp echo "test"
$ journalctl -f
-- Logs begin at Sat 2018-02-24 12:13:24 CET. --
Jul 25 13:56:08 mycomputer myapp[25213]: test
$ journalctl -f -t myapp
-- Logs begin at Sat 2018-02-24 12:13:24 CET. --
Jul 25 13:56:08 mycomputer myapp[25213]: test

How can I filter journalctl output on process name?

已采纳解答

原帖链接 · Merlijn Sebrechts · CC BY-SA 4.0

Just figured this out. You can use any systemd journal field as filter by specifying <FIELD_NAME>=<VALUE>.

The following fields are useful for this question:

_COMM=, _EXE=, _CMDLINE=

The name, the executable path, and the command line of the process the journal entry originates from.

So in order to filter on the command name, use journalctl -f _COMM=<command-name>

$ journalctl -f _COMM=echo
-- Logs begin at Sat 2018-02-24 12:13:24 CET. --
Jul 25 13:52:26 mycomputer echo[25098]: test
Jul 25 13:56:08 mycomputer myapp[25213]: test

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-07-25)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。