- Linux: How to send message to local user logged into X11?
- 5 Answers 5
- How to Send a Message to Logged Users in Linux Terminal
- How to Send Broadcast Message to Logged-in Users on Linux Terminals
- Send Messages to Logged-in Users Using the Wall Command
- Send Messages to a Specific Logged-in User
- How to Send Message to Logged User in Linux
- How to Send Message to Logged User in Linux
Linux: How to send message to local user logged into X11?
Is possible to send a message (popup window or something) to local user logged into X (xdm, fluxbox) from console ? For example: user1 is logged and using X/fluxbox, user2 logging into the same box by ssh to console. Now — what user2 have to do to send message to user1 ?
5 Answers 5
The xmessage tool lets you do exactly that; present a popup window to users with a text message inside.
Example: user2 logs into a BASH session on the box and issues:
export DISPLAY=':0.0' xmessage "some message here"
if you log into a TSCH session, it’d be something like this:
setenv DISPLAY ':0.0' xmessage "some message here'
Alternatively, you can send messages to terminal sessions in one of two ways:
Using wall (=warn all [users])
From the man page:
Wall displays the contents of file or, by default, its standard input, on the terminals of all currently logged in users.
If you want to target a specific user, use write . Again, man tells us:
The write utility allows you to communicate with other users, by copying lines from your terminal to theirs.
If a recipient ( user1 in my example) is logged into X11, and haven’t opened xterm or other terminal — will wall work too ? I think that user1 will not see messages.
I updated my answer to include the ‘xmessage’ solution. That will show a small window to the user, irrespective of whether they have a terminal open.
Incidentally, ‘apropos’ is a useful utility to know; it searches manual pages for the text you pass to it. Try running ‘apropos message’ and see what it returns.
I know xmessage but how to run it by user1 and get this small window opened on user2 ‘s screen ? is it even possible ?
As a rule, X11 sessions are usually started in a “private” mode, so you require one of two things: either, coöperation from user2 to allow you to access their screens, or superuser privileges to “break in” to their screens.
DANGER: Do keep in mind, once you have access to their screen, you could also do things like capture keystrokes (potentially including passwords) and take screenshots, so this is a big security risk.
In most cases it’s preferable to instead use a messaging tool or chat program for these things.
Coöperating
If user2 wants to allow user1 to access their screen, then first user2 must issue a command like:
This could potentially be added to a start-up script of some kind; I don’t know Fluxbox, but I assume it has a rc or session-start hook.
Once this has been issed, user1 can then write to user2 ‘s display, if they can find it.
If user2 is aware of this, they can always send it to user1 in some other way.
Finding another user’s Display
On a typical workstation, it’s unusual to have more than one or two users logged in; in which case, “guessing” that the display you want is 0, 1, or maybe 2 might be a workable solution.
However, for a more complete solution, let’s assume that you have a machine where very many users could be signed in, and try to find the one you want.
for proc in /proc/4*/ do if [ Xorg = $(< $proc/comm ) ] 2>/dev/null && \ [ $(id -u user2) -eq $(< $proc/loginuid) ] 2>/dev/null then for subproc in $( do echo "user2 display Hello, user2"
Sending a Notification instead
In the interests of completeness, the following works on Gnome desktop, at least. I don’t know if Fluxbox has a notification widget.
DISPLAY=:14.0 notify-send "Hello, user2"
This has a lot more user-friendly options for display, and probably will pop up in a rather friendlier way on the user’s screen.
I’d like to use notify-send (which is how I ended up here), but using DISPLAY=:N.n notify-send only works if I do it as the user I want to send it to — and if I do it from the GUI, lol (meaning it is totally useless). Otherwise notify-send either does nothing or blocks indefinitely. Did you actually test this when you wrote it?
It was working with whatever version of Gnome+Fedora were current in 2016, but I haven’t rechecked since. I often use notify-send from scripts but usually as «myself» … I suppose some sudo magic could work if the dbus system is more locked-down now?
This is a slightly «off the wall » suggestion.
Install espeak (or espeak-ng ) on the target machine from your ssh execute
espeak "The matrix has you"
Espeak is a text to speech engine, and will output to the console’s speakers. If the volume is not set to zero, this will cause the computer to speak to the local user.
For anyone who could not get notify-send to work by setting DISPLAY to that of the target user, you can use that or any other command by reading from a pipe that messages can be sent to.
#!/bin/bash dir=/home/you/notify-pipe/ fifo=$dir/notifications if [ ! -e $fifo ]; then # The '$dir' path must exist or mkfifo will fail. if [ ! -e $dir ]; then mkdir -p $dir if [ $? -ne 0 ]; then exit $?; fi fi mkfifo -p $fifo if [ $? -ne 0 ]; then exit $?; fi fi echo $BASHPID > $dir/bash.pid # All errors etc. from here on logged exec &>> $dir/log.txt date while [ -e $fifo ]; do read line < $fifo notify-send "$line" done
You can then run this in the background with setsid -f ./whatever.sh (or autostart it via your DE). Other users and system processes can then notify by writing to the FIFO (eg. "echo hello > /home/you/notify-pipe/notifications"). If your home is not publicly readable the pipe can be anywhere.
To stop it you'll have to kill it or delete the pipe. Beware that a pitfall of this is that if the pipe exists but nothing is reading from it (eg. the script), writing a message (eg. via echo ) will block until something does read it.
How to Send a Message to Logged Users in Linux Terminal
How can I send a messages to logged on users in a Linux server? If you are asking this question, then this guide will help you learn how to do that. We will demonstrate how to send a message to all or a specific logged on user, on the terminal in Linux.
Linux offers a variety of means for sending messages to users logged on to a server as explained in the two methods below.
In the first method, we will use wall command – write a message to all currently logged in users on the terminal as shown.
# wall "System will go down for 2 hours maintenance at 13:00 PM"
To disable the normal banner printed by wall, for example:
Broadcast message from [email protected] (pts/2) (Sat Dec 9 13:27:24 2017):
Add the -n (Suppress the banner) flag, this however, can only be used by the root user.
# wall -n "System will go down for 2 hours maintenance at 13:00 PM"
In the second method, we will use write command, which comes pre-installed on all if not most Linux distributions. It allows you to send a message to another user in the terminal using tty.
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.
That’s all! Do share with us other methods or commands for sending messages to all logged on users through the terminal in Linux. If you have any queries, please use the feedback form below.
How to Send Broadcast Message to Logged-in Users on Linux Terminals
Linux is a multi-user operating system that allows multiple users to log in and use the system. This implies that at any given time, you might have several users logged in.
Sometimes, you might need to send a message or notification to all the users without necessarily placing a phone call or sending them emails. This is mostly when you want to announce a maintenance task or instruct them to log out.
In this guide, we will demonstrate how you can send messages to all logged-in users in the system. This only applies to users who are logged in via a terminal window using an SSH client such as PuTTY.
Send Messages to Logged-in Users Using the Wall Command
The wall command is a command-line utility that displays messages to all logged-in users on the terminal.
The wall command takes the following basic syntax:
If no file is specified, then the wall command reads the message from standard input and broadcasts it to all logged-in users.
For example, the following command reads the message enclosed in quotation marks as the argument and sends it to all logged-in users
# wall "The system will be shutting down at 1500HRS for maintenance. Apologies for any inconvenience caused".
When viewed from a logged-in user (in this case bob), the message appears as shown on the terminal window.
To display a message from a file, invoke the wall command followed by the file name as shown.
This is how the user receives the message on the terminal.
Send Messages to a Specific Logged-in User
Alternatively, you can use the write command to send a message to a specific user. To list all the currently logged-in users, invoke the who command:
For example, to send a message to a user called winnie and notify her about a system restarting in the next 3 hours, run the following write command with the echo command.
$ echo "This system will be restarted in 3 hours" | write winnie
On the user’s terminal, the message will appear as shown.
Conclusion
We have covered various ways of sending a message or notification to logged-in users using the wall and write commands. We hope that you can now send messages to logged-in users without a problem.
How to Send Message to Logged User in Linux
Often Linux system administrators need to be able to send message to logged user in Linux. Although there are various chat applications that help you broadcast messages, there are very few commands that allow you to send messages only to logged users in Linux. In this article, we will learn how to send message to logged user in Linux.
How to Send Message to Logged User in Linux
You can use wall command to send message to logged user in Linux. Here is a sample command to inform all logged users about a 2-hour system downtime.
# wall "System will go down for 2 hours maintenance at 13:00 PM"
When you send the above message, here is what logged users will see on their screens. root@ubuntu will be replaced by your admin username,
Broadcast message from root@ubuntu (pts/2) (Sat Dec 9 13:27:24 2022): System will go down for 2 hours maintenance at 13:00 PM
If you want to disable the broadcast banner in the above message, use -n option.
# wall -n "System will go down for 2 hours maintenance at 13:00 PM"
Alternatively, you can also use write command to send message to users using tty. For this purpose, use who command to list all users in your system.
Here is an example to send message to user test1.
You will see a prompt to type your message. Press Ctrl+D after the message is typed.
wall is a one-to-many broadcasting message sender while write is a one-to-one messaging tool. You can use either of them depending on your requirement.
In this article, we have learnt how to send message to logged user in Linux. You can also use these commands in your shell script, if you want to automate the broadcast of your messages.