英文:
How can I negate the exit code of a command used in ExecCondition of a systemd service
问题
I would like to negate the exit code of a command used in ExecCondition of a systemd service. However, I cannot use a "!" before the command because this character is used by systemd for something slightly different (proceed even if the command fails [1]).
[Unit]
Description=Negated Exec Condition
[Service]
Type=oneshot
ExecCondition=/usr/bin/command # 如何否定退出码?
ExecStart=...
[Install]
WantedBy=default.target
[1] https://www.freedesktop.org/software/systemd/man/systemd.service.html
英文:
I would like to negate the exit code of a command used in ExecCondition of a systemd service. However, I cannot use a "!" before the command, because this character is used by systemd for something slightly else (proceed, even if command fails [1]).
[Unit]
Description=Negated Exec Condition
[Service]
Type=oneshot
ExecCondition=/usr/bin/command # How can I negate the exit code?
ExecStart=...
[Install]
WantedBy=default.target
[1] https://www.freedesktop.org/software/systemd/man/systemd.service.html
答案1
得分: 0
你可以运行 shell。
ExecCondition=/bin/sh -c '! "$@"' -- /usr/bin/command
英文:
You could run the shell.
ExecCondition=/bin/sh -c '! "$@"' -- /usr/bin/command
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论