Linux write to all terminals

How do I program Python so that it outputs to all terminals in Linux

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?

I migrated this here instead of S.O. because, although it involves programming, I think this particular question will get better answers here.

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.

2 Answers 2

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.

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.

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.

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.

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 

Источник

Читайте также:  Can we install sql server on linux

Linux write command

Computer Hope

On Unix-like operating systems, the write command sends a message to another user.

This page covers the Linux version of write.

Description

The write utility lets you communicate with other users by copying lines from your terminal to theirs.

When you run the write command, the user you are writing to gets a message of the format:

Any further lines you enter are copied to the specified user’s terminal. If the other user wants to reply, they must run write as well.

When you are done, type an end-of-file or interrupt character. The other user sees the message ‘EOF’ indicating that the conversation is over.

You can prevent people (other than the super-user) from writing to you with the mesg command.

If the user you want to write to is logged in on more than one terminal, you can specify which terminal to write to by specifying the terminal name as the second operand to the write command. Alternatively, you can let write select one of the terminals and it will pick the one with the shortest idle time. So, if the user is logged in at work and also dialed up from home, the message goes to the right place.

The traditional protocol for writing to someone is that the string ‘-o’, either at the end of a line or on a line by itself, means that it is the other person’s turn to talk. The string ‘oo’ indicates the person believes the conversation to be over.

Syntax

write user [tty]

Options

user The user to write to.
tty The specific terminal to write to, if the user is logged in to more than one session.

Examples

Write a message to the user hope. After entering this command, you will be placed on a blank line, where everything you type will be sent to the other user (line by line). Typing the interrupt character (Ctrl-C, by default) returns you to the command prompt and end the write session.

Читайте также:  Linux process create time

Write a message to the user hope on terminal tty7.

mesg — Control if (non-root) users can send messages to your terminal.
talk — Talk with other logged in users.
wall — Send a message to all logged-in users.
who — Report which users are logged in to the system.

Источник

How do you send a message to all terminals in Linux?

How do you send a message to all terminals in Linux?

After typing message, use ctrl+d to send it to all users. This message will show on the terminal of all users who are currently logged in.

How do I broadcast a message on a Linux server?

First check the all logged on users with the who command as shown. There are currently two users are active on the system (tecmint and root), now the user aaronkilik is sending a message to the root user. $ write root pts/2 #press Ctrl+D after typing the message.

How do I enable messages on Linux?

Each user can enable/disable other users ability to send messages to them using the command mesg. This command can be put into your . bashrc or . login file (depending on shell).

How do I enable messages in Ubuntu?

  1. mesg [y|n]
  2. Mesg controls the access to your terminal by others. It’s typically used to allow or disallow other users to write to your terminal (see write(1)).
  3. y Allow write access to your terminal.
  4. Mesg assumes that its standard input is connected to your terminal.
  5. talk(1), write(1), wall(1) Feb 26, 2001 MESG(1)

How do you write in terminal?

When you see your username followed by a dollar sign, you’re ready to start using command line. Linux: You can open Terminal by directly pressing [ctrl+alt+T] or you can search it up by clicking the “Dash” icon, typing in “terminal” in the search box, and opening the Terminal application.

How do I write on Linux?

How to Create/Write a Simple/Sample Linux Shell/Bash Script

  1. Step 1: Choose Text Editor. Shell scripts are written using text editors.
  2. Step 2: Type in Commands and Echo Statements.
  3. Step 3: Make File Executable.
  4. Step 4: Run the Shell Script.
  5. Step 5: Longer Shell Script.
  6. 2 Comments.

How do you write a command in Linux terminal?

Linux operating system allows users to create commands and execute them over the command line. To create a command in Linux, the first step is to create a bash script for the command. The second step is to make the command executable. Here, bashrc means run the Bash file.

Читайте также:  Read execute permissions linux

How do you write a command in Unix?

The syntax for the write command is:

  1. $ write user [tty] message.
  2. $ write root pts/7 test.
  3. Message from [email protected] on pts/8 at 11:19 test.

What are different types of commands in Linux?

Here is a list of basic Linux commands:

  • pwd command. Use the pwd command to find out the path of the current working directory (folder) you’re in.
  • cd command. To navigate through the Linux files and directories, use the cd command.
  • ls command.
  • cat command.
  • cp command.
  • mv command.
  • mkdir command.
  • rmdir command.

Источник

Writing to multiple remote terminals over SSH

Let’s say I am SSH’ing to multiple remote machines. I’d like to send commands to all the machines through one interface. I was thinking of opening a named pipe whose output would be piped to each machine I SSH into. That way if I echo «ls -l» > namedpipe , then the command would run on each machine. I tried this, but it didn’t work. Any suggestions on how can I have one terminal from which I could interact with all the remote machines?

2 Answers 2

GNU Parallel is the way to go. There are lots of examples on SO and elsewhere, also using named pipes when needed. Other tools are mentioned and compared in the parallel manpage.

As to your example, what you want can be done as simply as

parallel ssh <> "ls -l" . user1@machine1 user2@machine2 . 

Some linux distributions come with a configuration file (usually /etc/parallel/config ) where the option —tollef is set by default. If this is your case and you don’t want to change, you must use — instead of . in the first example above, or, alternatively, use the —gnu option to override —tollef .

Equivalently, if you create a file called remotelist containing

user1@machine1 user2@machine2 
parallel -a remotelist ssh <> "ls -l" 

or, as noted by a comment below,

parallel --nonall --slf remotelist ls -l 

the —slf option (short for —sshloginfile ) allows stuffing more information in the remotelist file: comments, number of processors to use on each remote host, and the like.

You might also consider the —tag option, which prepends each output line with the name of the host it originates from.

Источник

Оцените статью
Adblock
detector