Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could run the shell.

ExecCondition=/bin/sh -c '! "$@"' -- /usr/bin/command
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading