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:


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.

  • Tried calling /bin/date?
    – stoney
    Jul 7 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?
    – LaVache
    Jul 8 at 0:21
  • I meant calling it with full path
    – stoney
    Jul 19 at 11:46
  • 1
    @stoney Ah ok. Yeah that doesn't work either. Systemd unit files don't support $() in the first place.
    – LaVache
    Jul 20 at 6:56


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy