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

systemd StandardOutput to a file _and_ to the journal?

· 52CE 我爱测

I am regularly doing a long running (~5 day) data processing programme. I'm using Ubuntu and running the command with a systemd transient task via systemd-run --unit data_import /path/to/my-script.sh . It's working well. I can lo…

问题原文

原帖链接 · Amandasaurus · CC BY-SA 4.0

I am regularly doing a long running (~5 day) data processing programme. I'm using Ubuntu and running the command with a systemd transient task via systemd-run --unit data_import /path/to/my-script.sh. It's working well. I can look at the logging standard output of the script with journalctl -u data_import.service.

I would like the stdout (& stderr) from the script to be saved to a file as well as the systemd journal. I see that systemd-run --unit data_import -p "StandardOutput=file:/path/my-logging-file.txt … will save stdout to that file. However it won't log to the journald. I tried to provide the argument twice systemd-run -p "StandardOutput=file:/path/my-logging-file.txt" -p "StandardOutput=journal" …, but that didn't work.

Is it possible with systemd to log the stdout to a file and to the systemd journal? (likewise for stderr?)

Ubuntu 18.04 & 20.04, systemd v250. or v245 etc

已采纳解答

原帖链接 · asktyagi · CC BY-SA 4.0

I guess we can't but found one reference https://www.freedesktop.org/software/systemd/man/systemd.exec.html#StandardOutput= which might help (pay attention to Takes one of string).

Controls where file descriptor 1 (stdout) of the executed processes is connected to. Takes one of inherit, null, tty, journal, kmsg, journal+console, kmsg+console, file:path, append:path, truncate:path, socket or fd:name.

Though we can change default standard output type.

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

资料来源与适用范围

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

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

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