How to Pipe Output to a File When Running as a Systemd Service? How to Pipe Output to a File When Running as a Systemd Service? linux linux

How to Pipe Output to a File When Running as a Systemd Service?


systemd.service(5) says:

ExecStart=

Commands with their arguments that are executed when this service is started.

So, systemd runs your /apppath/appname with args >, /filepath/filename, 2>&1

Try:

ExecStart=/bin/sh -c '/apppath/appname > /filepath/filename 2>&1'


Try:

ExecStart=/usr/bin/sh -c "/apppath/appname > /filepath/filename 2>&1"

ExecStart requires the first argument to be a binary (no exceptions), and doesn't allow pipes or redirection. Therefore, use ExecStart to start a shell within which you can do all the fancy things required.