gpt4 book ai didi

bash - Systemctl bash 变量

转载 作者:行者123 更新时间:2023-12-04 19:27:45 26 4
gpt4 key购买 nike

我试图让这个变量工作,但我总是遇到关于 systemd-escape 的错误。虽然我转义了特殊字符,但变量不起作用:

status="systemctl status syslog-ng | grep Active: | sed 's/.*: //' | sed 's/since.*//g'"
我得到的结果在这里:
Invalid unit name "|" was escaped as "\x7c" (maybe you should use systemd-escape?)
Invalid unit name "|" was escaped as "\x7c" (maybe you should use systemd-escape?)
Invalid unit name "'s/.*:" was escaped as "\x27s-.*:" (maybe you should use systemd-escape?)
Invalid unit name "|" was escaped as "\x7c" (maybe you should use systemd-escape?)
Invalid unit name "'s/since.*//g'" was escaped as "\x27s-since.*--g\x27" (maybe you should use systemd-escape?)
Unit \x7c.service could not be found.
Unit grep.service could not be found.
Unit Active:.service could not be found.
Unit \x7c.service could not be found.
Unit sed.service could not be found.
Unit \x27.mount could not be found.
Unit \x7c.service could not be found.
Unit sed.service could not be found.
● syslog-ng.service - System Logger Daemon
Loaded: loaded (/usr/lib/systemd/system/syslog-ng.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2021-10-11 14:01:23 CEST; 26min ago
Docs: man:syslog-ng(8)
Main PID: 3020944 (syslog-ng)
Tasks: 3 (limit: 101081)
Memory: 8.9M
CGroup: /system.slice/syslog-ng.service
└─3020944 /usr/sbin/syslog-ng -F -p /var/run/syslogd.pid

Oct 11 14:01:23 syslog-ng systemd[1]: Starting System Logger Daemon...
Oct 11 14:01:23 syslog-ng syslog-ng[3020944]: [2021-10-11T14:01:23.798405] Plugin module not found in 'module-path'; module-path='/usr/lib64/syslog-ng'>
Oct 11 14:01:23 syslog-ng syslog-ng[3020944]: [2021-10-11T14:01:23.801271] Plugin module not found in 'module-path'; module-path='/usr/lib64/syslog-ng'>
Oct 11 14:01:23 syslog-ng syslog-ng[3020944]: [2021-10-11T14:01:23.801828] Plugin module not found in 'module-path'; module-path='/usr/lib64/syslog-ng'>
Oct 11 14:01:23 syslog-ng syslog-ng[3020944]: [2021-10-11T14:01:23.808340] WARNING: With use-dns(no), dns-cache() will be forced to 'no' too!;
Oct 11 14:01:23 syslog-ng systemd[1]: Started System Logger Daemon.
我只想将我的 syslog-ng 的状态作为变量

最佳答案

建议关注 systemd service unit definition documentation .
Command lines 中所述部分。

This syntax is inspired by shell syntax, but only the meta-characters and expansions described in the following paragraphs are understood, and the expansion of variables is different. Specifically, redirection using "<", "<<", ">", and ">>", pipes using "|", running programs in the background using "&", and other elements of shell syntax are not supported.


我们不能假设 bash也不是 sh语法/规则写作 systemd服务单位。
环境变量最好静态定义。
如果您需要将值存储在动态变量中。我们建议创建一个脚本 service-unit-xyx.bash执行所有必需的分配并最终运行目标服务。
使用单个脚本 service-unit-xyx.bash您可以轻松地记录和调试每一行。
最终执行 service-unit-xyx.bash ExecStart= 中的完整路径脚本命令。
使用执行脚本 service-unit-xyx.bash还简化了服务单元的开发,来自 systemd服务单元文件到 bash/sh 脚本开发。
也可以使用 ExecStartPre= , ExecStartPost=控制服务运行时环境的命令。
阅读并关注互联网上的示例服务单元。
所有命令/脚本都应指定绝对路径引用。

关于bash - Systemctl bash 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69526298/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com