0

I'm trying to setup a systemd timer on a debian server doing a rsync remote backup. I wrote a systemd service file:

[Unit]
Description=My Backup Service

[Service]
ExecStart=/usr/bin/sshpass -p "mypassword" /usr/bin/rsync --log-file=/var/log/mybackup.log --rsync-path=/bin/rsync -avE --delete /var/www/* admin@192.168.1.3:/mybackup

[Install]
WantedBy=default.target

When I start the service, I get the following error:

Aug 13 23:21:44 debian systemd[1]: Started Backup Service.
Aug 13 23:21:44 debian sshpass[12564]: Unexpected remote arg: admin@192.168.1.3:/mybackup
Aug 13 23:21:44 debian sshpass[12564]: rsync error: syntax or usage error (code 1) at main.c(1348) [sender=3.1.1]
Aug 13 23:21:44 debian systemd[1]: mybackup.service: main process exited, code=exited, status=1/FAILURE
Aug 13 23:21:44 debian systemd[1]: Unit mybackup.service entered failed state.

Running the command line manually gives no errors. Does systemd parse the command line in a different way?

  • 2
    Could be the wildcard in /var/www/* is giving you problems. Try encasing the command inside a shell, something like ExecStart=/bin/sh "command" – ojs Aug 14 '17 at 0:33
  • Well, the complete syntax is ExecStart=/bin/sh -c "/usr/bin/sshpass -p …" It works. Thank you. But the question is still: How does ExecStart handle the command string? – awado Aug 15 '17 at 18:47
1

Running the command line manually gives no errors. Does systemd parse the command line in a different way?

Yes. It doesn't spawn a shell.

Furthermore, variables work differently from a shell. ${FOO} expands to a single word, while $FOO splits it on whitespace (the shell would use double quotes to define whether word splitting happens or not.)

There are also some differences on how single and double quotes work.

systemd will also expand % specifiers such as %i, %n, %h, etc.

You can find the full documentation for how systemd handles command lines here: https://www.freedesktop.org/software/systemd/man/systemd.service.html#Command%20lines

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.