Pipe output of script through Exec in systemd service?
Yes, you can write directly to the target directory.
You can't really use a pipe directly as part of an ExecStart=
command, since systemd doesn't really implement a full shell. But you can invoke a shell explicitly, which would make it work. For example:
ExecStart=/bin/sh -c '/usr/bin/atom | /Path/To/Script/Todays_Dir Todo.md'
But it turns out this is a bit awkward, since Todays_Dir
would end up having to run cat
to write to the full path of its argument. In effect, you don't really need a pipe here, you just need to determine the name of a directory and run atom
with the proper redirect.
Consider instead just implementing everything in a script and running it directly from the systemd unit.
Something like:
#!/bin/bash
set -e # exit on error
dated_dir=$HOME/Documents/Journals/$(date +%Y/%-m/%-d)
mkdir -p "${dated_dir}"
exec atom >"${dated_dir}/ToDo.md"
And then in the systemd unit:
ExecStart=/Path/To/Script/GenerateMarkdownToTodaysDir.sh
The exec
at the end of the shell script makes the shell replace itself with the atom
program, so that systemd will end up running atom
directly after setup. For this case it's not that important, so it could be omitted (especially if you're interested in doing some kind of post-processing after the atom
run.)