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 ?

1
  • I'm asking about Ubuntu Server 21.04 – Liwinux May 13 at 10:02
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

2
  • * It is better to do anything you want to do that requires users to be logged off after "business hours".* is absolutely true, but impossible if your business hours are 24/7 or undefined. – Chris H May 13 at 8:18
  • Thank you for those informations. Of course those type of actions will take place after "business action". My main concern here was to know if I have to log everyone off manually or if there is a command that performs the same action when using the shutdown command like disconnecting everyone except the admin. – Liwinux May 13 at 10:02

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.