1

I've created a systemd service unit file, and since systemd version 240+, we can just set the STDOUT + STDERR outputs to go directly into files, like this:

StandardOutput=append:/tmp/my-service.log
StandardError=append:/tmp/my-service.log

Is there a way for me to add in the current timestamp of when the service was started into these filenames?

e.g. instead of /tmp/my-service.log, each time the service starts, it's something like: /tmp/my-service.2022-07-07_114035.log

If it was similar to a shell script, I could do something like:

StandardOutput=append:/tmp/my-service.$(date +%Y-%m-%d_%H%M%S).log
StandardError=append:/tmp/my-service.$(date +%Y-%m-%d_%H%M%S).log

...but that doesn't work in systemd config files.

4
  • Tried calling /bin/date? Commented Jul 7, 2022 at 12:53
  • @stoney Well yeah that's exactly what I'm trying to do, as shown under "If it was similar to a shell script, I could do something like:". I'm asking how to dynamically call it inside a systemd config file (every time the service restarts) and set it in the StandardOutput= and StandardError= fields? Commented Jul 8, 2022 at 0:21
  • I meant calling it with full path Commented Jul 19, 2022 at 11:46
  • 1
    @stoney Ah ok. Yeah that doesn't work either. Systemd unit files don't support $() in the first place. Commented Jul 20, 2022 at 6:56

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.