1

Everything I have tried either doesn't work or results in an error while starting the service.

This is what chapt GPT suggested and it resulted in an error...

ExecStartPre=/bin/bash -c 'echo "Your message" >/dev/stdout' 

The error I saw was:

"/bin/bash: /dev/stdout: No such device or address"

2
  • I’m voting to close this question because From the tag: systemd questions should be for programming questions using systemd or its libraries. Questions about configuring the daemon (including writing unit files) are better directed to Unix & Linux: unix.stackexchange.com. Please delete this. Commented Apr 17, 2023 at 7:52
  • You should make note that, on meta, chatgpt recommended not using chatgpt because it is not reliable and often wrong. Commented Apr 17, 2023 at 7:53

1 Answer 1

2

In short, you don't. Services do not produce interactive output and are not attached to the original 'systemctl' terminal in any way – they're services, and their output goes to the system log (journal). Anything you 'echo' will be visible in systemctl status of the service.

(Second, redirecting something to > /dev/stdout is completely redundant, as the text from 'echo' is already being written to stdout, so you're just redirecting stdout to itself. It's just that the stdout of a service is not attached to your terminal – it's attached to a log pipe.

The redirection fails with an error message because of the strange way /dev/fd works on Linux; it's a bug that went unfixed for two decades and will never be fixed. Services do have an "stdout", but it is attached to an anonymous pipe, not a file, and cannot be re-opened the way /dev/fd tries to do it.)

Sign up to request clarification or add additional context in comments.

4 Comments

Bummer, I was just hoping to send a message to future me whenever the service was started. I guess I could probably build a bash wrapper that starts the service it self but didn’t want to do that.
If it's critical, you could send it to all terminals via wall, assuming your terminal emulator opts in (i.e. if the terminal windows show up in who or w). Otherwise, make something in ExecStartPre that sends you an email or a chat message. (I have syslog-ng set up to forward "alert"-level syslog messages to a Discord webhook, so my tools can do logger -p alert ... and it results in a push notification.)
Thank you! May I ask for a reference for the bug at some bug tracker if possible?
@Artfaith: It largely predates Linux's Bugzilla. web.archive.org/web/20111011030303/http://yarchive.net/comp/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.