I am programming a python program for the raspberry pi. Is there a way for me so that when the raspberry pi outputs text, it will show up on all terminals that are currently remotely logged in via SSH?

  • 1
    I migrated this here instead of S.O. because, although it involves programming, I think this particular question will get better answers here. – goldilocks Jun 29 '15 at 13:58
  • Can you install tmux or screen? Both can run a session in the background and you can just connect to (or disconnect from) it when needed. – Kevin Jun 29 '15 at 14:41

You can try to use the wall program, but the logged in users may be able to override that and avoid seeing any wall messages. Alternately, you can attempt configure and use syslog to send a message from a given facility to the * location, which (in my experience) will show up on all logged in shells.

  • 1
    Using a syslog interface (I presume python has one) with sufficient priority ("emergency") should get the output posted everywhere including ssh logins on most systems by default (you shouldn't have to configure syslog) -- and it seems you don't even need special privileges to do so... – goldilocks Jun 29 '15 at 14:11
  • You shouldn't have to configure syslog, no, but there's no guarantee that syslog will have a default configuration or a sufficient configuration for this. I myself tend to disable the "emergency" syslog spam on all my systems - if I don't know about an emergency without syslog telling me about it, I have bigger problems. – John Jun 29 '15 at 14:13
  • The fact that this method is dependent on syslog configuration is indeed important. Its advantage over writing directly to the tty's/pty's is that you can target everyone without needing root privileges. – goldilocks Jun 29 '15 at 14:24

In a very simplistic way: you can look at all the pseudo-ttys in use and write to all of them. Use who to list all the current logins and their tty, eg:

$ who
me       tty1         Jun  1 07:09
brian    pts/0        Jun  1 07:15 (:pc1)
john     pts/1        Jun  1 07:15 (:pc88)
sue      pts/2        Jun  1 07:15 (:pc7)

The 2nd column shows e.g. /dev/pts/0 is being used by login brian. You can simply write to it, if you have sufficient permission, eg:

echo 'Msg from me: hello!' >/dev/pts/0

On my system (not a pi, sorry), you need to be in group tty, or be root:

$ ls -l /dev/pts/0
crw--w---- 1 brian tty 136, 4 Jun 28 20:55 /dev/pts/0

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.