I try use date output as part of log file name in systemd unit. Here example:

Description=TCS minetest server unit

ExecStart=/home/tcs/minetest/bin/minetestserver --worldname world --logfile /home/tcs/logs/debug_$$(date +%%Y_%%m_%%d).txt
ExecReload=/bin/kill -HUP $MAINPID


But I get the log file:

ls /home/tcs/logs/

How I can use current date for log filename?


This type of syntax is not directly supported, as explained on the man page for system.service:

This syntax is inspired by shell syntax, but only the meta-characters and expansions described in the following paragraphs are understood, and the expansion of variables is different. Specifically, redirection using "<", "<<", ">", and ">>", pipes using "|", running programs in the background using "&", and other elements of shell syntax are not supported.

The 'following paragraphs' mainly include basic environment variable substitution, path searching, and some C escapes.

In general, you can get around these restrictions by writing your own shell script which sets up the process, and then specifying that script as the ExecStart option on the systemd service.

In your specific case, you should be able to get the date substitution to work by passing it explicitly to a shell:

ExecStart=/bin/bash -c '/home/tcs/minetest/bin/minetestserver --worldname world --logfile /home/tcs/logs/debug_$(date +%Y_%m_%d).txt'

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.