【问题标题】:Piping systemd output into a file将 systemd 输出通过管道传输到文件中
【发布时间】:2016-07-06 15:52:00
【问题描述】:

我正在尝试使用 >> 将 systemd 中命令的输出通过管道传输到文件 比如this问题

不幸的是,我得到的结果表明我正在运行的原始命令使用 >> 作为开关并且无法识别它。

我之前使用 upstart 做过同样的事情,但没有遇到这个错误:(

这是我的 systemd.service 文件:

[Unit]
Description=ss13_server
[Service]
User=ss13
WorkingDirectory=/home/ss13/ss13
ExecStart=/usr/local/byond/bin/DreamDaemon /home/ss13/ss13/baystation12.dmb 25565 -trusted >> /home/ss13/ss13-log
Restart=on-failure
RestartSec=90s

我得到的结果是:

Dream Daemon: invalid option '>>'

通常我会假设 DreamDaemon 与 >> 不兼容,但正如我所说,我过去曾成功使用过这种方法;如果我手动运行命令,它也可以工作。

感谢您提供的任何帮助。

【问题讨论】:

  • 在未来,systemd 问题更适合unix.stackexchange.com,因为 StackOverflow 专注于编程问题。
  • 这不起作用,因为>> 是一个shell 脚本选项。 Systemd 直接运行命令,无需任何 shell。但你当然可以做类似ExecStart=bash "/mycommand >>myfile" 的事情。
  • @Marki555:我们需要绝对路径,所以应该是ExecStart=/bin/bash -c "<insert_command_here>"

标签: logging systemd piping


【解决方案1】:

将命令行放入文件中:

#!/bin/bash
/usr/local/byond/bin/DreamDaemon /home/ss13/ss13/baystation12.dmb 25565 -trusted >> /home/ss13/ss13-log

然后让ExecStart= 引用该文件。

【讨论】:

  • 嗯,会的。谢谢!
猜你喜欢
  • 1970-01-01
  • 2019-01-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多