I am trying to write a file to disk as part of the ExecStartPre
command of a systemd unit file.
This is what I am using:
[Unit]
Description=My service
[Service]
Restart=always
StartLimitInterval=0
ExecStartPre=/usr/bin/cat <<EOFDefaults > /tmp/test
option1=value1
option2=value2
EOFDefaults
ExecStart=/run/some/command
Since that's a multi-line command, I get the following error when testing it with systemd-analyze verify myservice.service
.
So, I tried to escape the multi-lines:
[Unit]
Description=My service
[Service]
Restart=always
StartLimitInterval=0
ExecStartPre=/usr/bin/cat <<EOFDefaults > /tmp/test \
option1=value1 \
option2=value2 \
EOFDefaults
ExecStart=/run/some/command
When testing the unit file, I get the following error: Invalid escape sequences in command line:
How does one use cat to write multi-line content to a file as part of a systemd unit file command?