0

Is there a command that lets me send messages to other logged-in users? I would like for example to notify users before I shutdown or restart the server.

2 Answers 2

0

One of the oldest commands which allows you to send messages to other users is called write.

In order for your users to be able to get messages using write, you'll have to enable it (as root).

Running just mesg will show you if it's enabled or not. mesg y to enable it. mesg n to disable it.

Then, to send messages: run who to see a list of users who are currently logged into the machine and in the second column you'll find their tty number:

[root@centolel ~]# who
root     pts/1        2017-03-15 19:22 (10.13.0.2)
lel      pts/4        2017-03-15 19:30 (10.13.0.2)

Then, run:

write [user] [tty]

And it will let you send messages directly to the user's terminal.

Example:

write lel /dev/pts/4

Then start typing your message.

3

wall is another alternative, and is used as follows:

sudo wall 'rebooting in 5 minutes'

From the man page:

NAME
       wall - write a message to all users

SYNOPSIS
       wall [-n] [-t timeout] [message | file]

DESCRIPTION
       wall  displays  a  message, or the contents of a file, or otherwise its standard input, on the terminals of all currently logged in users.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .