Skip to main content
5 of 9
added 23 characters in body
gapsf
  • 624
  • 4
  • 7

Create two systemd units and one script.

First unit:

/etc/systemd/system/are-users-logged.timer [Unit] Description=Start check for logged users [Timer] OnBootSec=15min Unit=shutdown-ifno-logged-users [Install] WantedBy=timers.target 

runs shutdown-ifno-logged-users.service once after 15min from the boot.

Second unit:

/etc/systemd/system/shutdown-ifno-logged-users.service [Unit] Description=Shutdown if there are no logged users [Service] Type=oneshot ExecStart=script_to_check_logged_user 

starts your script to check logged users.

In your script parse output of loginctl --no-pager list-users or maybe even who -q and shutdown if there is no user logged.

gapsf
  • 624
  • 4
  • 7