1

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

[Unit]
Description=TCS minetest server unit

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

[Install]
WantedBy=multi-user.target

But I get the log file:

ls /home/tcs/logs/
'debug_$(date'

How I can use current date for log filename?

1
3

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.