5

I want to do some maintenance on a server but in order to do that I need all users to be logged off. But I want to send I message (like shutdown do when you want to shutdown the system) to all the users to save their work and after that, log everyone off.

For a better understanding, I need the same function as the command shutdown (can send a warning message following the situation) except that instead of shutting down the system, it just logs everyone off.

Is there such command in linux ?

Liwinux
  • 53

1 Answers1

5

I would advice against these kind of actions: you will piss of the users of the system. It is better to do anything you want to do that requires users to be logged off after "business hours".

If you want to log a user out you can use

sudo pkill -9 -u {user}

but this will destroy anything that was not saved.

On a server there are 2 commands you can use to send messages wall and write:

$ wall "System will go down in 5 minutes. Please log off."

will send a message to ALL users or ...

$ write root tty7
System will go down in 5 minutes. Please log off. 
<control>d>

will send a message to user root on tty7. Sending a message though does not mean they read it, or act upon it. You can not force a save on anything that is not saved yet.

To be complete: you can also use command line to send a message to a desktop.

DISPLAY=:0.0 notify-send "System will go down in 5 minutes. Please log off."

enter image description here

Rinzwind
  • 309,379