You are not logged in.

#1 2018-06-24 15:45:41

BelowZero
Member
Registered: 2018-03-13
Posts: 59

[Solved] Trying to use spaces in systemd command lines

I have a service which looks like the following:

[Unit]
Description=Borg User Backup
 
[Service]
Type=simple
Nice=19
IOSchedulingClass=2
IOSchedulingPriority=7
ExecStartPre=/usr/bin/borg break-lock $REPOSITORY
ExecStart=/home/$USER/Backup Files/Borg Backup/borg-backup.sh

The service is failing becaues the path contains spaces.  I've tried substituting a backslash and a space, but that does not work. Neither does quotation marks.  Any idea how I can avoid having to rename my folders?

Last edited by BelowZero (2018-06-24 16:30:58)

Offline

#2 2018-06-24 15:48:31

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [Solved] Trying to use spaces in systemd command lines

Are you sure that it doesn't work with quotes?

Is it not just the fact that you're using variables which probably aren't set that's causing the issue?


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#3 2018-06-24 15:48:57

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,772

Re: [Solved] Trying to use spaces in systemd command lines

BelowZero wrote:

The service is failing becaues the path contains spaces.

Can you prove that assertion?  Or is it an assumption?

As a test, can you copy the file to a directory that does not have spaces and change your script to start it from there?  Does it work in that case?


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#4 2018-06-24 15:55:01

loqs
Member
Registered: 2014-03-06
Posts: 17,320

Re: [Solved] Trying to use spaces in systemd command lines

systemd-escape path\ with\ spaces
path\x20with\x20spaces

Not relevant as not a unit name issue see post #7

Last edited by loqs (2018-06-24 16:19:06)

Online

#5 2018-06-24 16:02:27

BelowZero
Member
Registered: 2018-03-13
Posts: 59

Re: [Solved] Trying to use spaces in systemd command lines

Good questions.  Should the quotation marks go around the specific folder with spaces, or around the entire path?  First, I'm going to verify that it works if I rename my folders.  Then I'll experiment to see where the spaces should go.  Using a backslash results in this error:

Jun 24 09:29:33 XPS systemd[1]: /etc/systemd/system/borg-backup.service:10: Executable path contains special characters: /home/$USER/Backup\ Files/Borg\>

Offline

#6 2018-06-24 16:06:39

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [Solved] Trying to use spaces in systemd command lines

Slithery wrote:

Is it not just the fact that you're using variables which probably aren't set that's causing the issue?


This.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#7 2018-06-24 16:15:17

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: [Solved] Trying to use spaces in systemd command lines

Right, because the literal string '$USER' is not part of a directory name, and you've escaped the dollar sign. But why on earth are you using $USER when systemd natively supports "%h":

/home/$USER/Backup Files/Borg Backup/borg-backup.sh

vs.

%h/Backup\x20Files/Borg\x20Backup/borg-backup.sh

It is your great fortune that $USER works at all, due to https://www.freedesktop.org/software/sy … 0processes

Unfortunately, $REPOSITORY most emphatically does not exist.

Also I don't see where you've specified that this is being run with systemctl --user, and if it is being run as root, then $USER will be the root user...

Also systemd does not use shell interpretation, see https://www.freedesktop.org/software/sy … nd%20lines for quoting rules.

Last edited by eschwartz (2018-06-24 16:17:22)


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#8 2018-06-24 16:30:42

BelowZero
Member
Registered: 2018-03-13
Posts: 59

Re: [Solved] Trying to use spaces in systemd command lines

Yes, you were right.  It failed because of the variables used, and I misread the journalctl errors.  I've made the corrections and everything seems in order.

Offline

Board footer

Powered by FluxBB