1

On the server that I use we have a systemd service that is responsible for starting/stopping/restarting something but the interaction with the service is designed in an interactive way so for example if I try to restart the service $ systemctl restart foo.service it asks me for a username and password interactively. What I want to achieve is to have a script or some other way that wraps the service so I can call it like this: script.sh <restart/start/stop> <username> <password>. This would allow me to automate some things.

3
  • 1
    Is the username and password asked from the foo service, or from systemctl? If you were to run systemctl as root would you still get prompted for the username and password? Commented Mar 28, 2019 at 8:39
  • Yes it’s from the service itself @roaima
    – Mihai
    Commented Mar 28, 2019 at 8:42
  • 2
    Does this service not provide you with an option to give these bits of data in some other form, like in a configuration file?
    – Kusalananda
    Commented Mar 28, 2019 at 10:50

1 Answer 1

2

$ printf 'username\npassword\n' | systemctl restart foo.service

1
  • 1
    Are you certain that the service would read from its standard input?
    – Kusalananda
    Commented Mar 28, 2019 at 10:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .