Skip to content
Advertisement

Bash: Date-epoch with systemd

I execute the following line in a bash console.

JavaScript

The content of my.log is as expected.

JavaScript

Now I change the timestamp to epoch (format-code +%s).

JavaScript

File is

JavaScript

As expected again.

But if I put this command line into systemd it would fail.

JavaScript

produces

JavaScript

Must be a problem with the format-code of date. If I remove the +%s then it is as expected (normal date-format and no epoch) with systemd too.

Any suggestions what is wrong with my command? Thanks!

Advertisement

Answer

The %-secuences are replaced by systemd. From systemd.unit manual:

Specifiers

“%s” User shell This is the shell of the user running the service manager instance. In case of the system manager this resolves to “/bin/sh”.

%s is substituted for /bin/sh, and date +/bin/sh returns /bin/sh.

Do:

JavaScript

Using backticks ` is discouraged. Use $(...) instead. bash hackers wiki deprecated and obsolete syntax

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement