[systemd-devel] Append to logfile with year-month

Donald Buczek buczek at molgen.mpg.de
Thu Aug 24 11:17:06 UTC 2023


Consider the ugly

ExecStart=bash -c "whatever > /var/log/root/aptCacheUsage_$(date +%%Y-%%m).log 2>&1"

or

ExecStart=bash -c "whatever | cronolog /var/log/root/aptCacheUsage_%%Y-%%m.log 2>&1"

Best
  Donald


On 8/24/23 9:48 AM, Cecil Westerhof wrote:
> In a service file I can use:
>     StandardOutput=append:/var/log/root/aptCacheUsage.log
> 
> but I want to use something like:
>     StandardOutput=append:/var/log/root/aptCacheUsage_$(date +%%Y-%%m).log
> 
> Did does not work, because this puts it in:
>     /var/log/root/aptCacheUsage_$(date +%Y-%m).log
> 
> Is there a way I can put it in:
>     /var/log/root/aptCacheUsage_2023-08.log
> 
> while it would automatically next month go into:
>    /var/log/root/aptCacheUsage_2023-09.log
> 
> I could of-course put it into:
>     /var/log/root/aptCacheUsage.log
> 
> and at the beginning of the month move it if it exists with a timed service, but I really would not like that kind of solution.
> 
> -- 
> Cecil Westerhof


-- 
Donald Buczek
buczek at molgen.mpg.de
Tel: +49 30 8413 1433


More information about the systemd-devel mailing list