系统不活动时会激活哪个特定脚本?脚本如何知道系统在配置的时间内处于不活动状态?
我需要该脚本,以便我可以检查是否有人通过 SSH 登录,并防止脚本实际挂起机器。
答案1
自动暂停现在由systemd-服务,尤其是其登录经理。
从其手册页中:
DESCRIPTION
systemd-logind is a system service that manages user logins. It is
responsible for:
· Keeping track of users and sessions, their processes and their idle
state
· Creating control groups for user processes
· Providing PolicyKit-based access for users to operations such as
system shutdown or sleep
· Implementing a shutdown/sleep inhibition logic for applications
· Handling of power/sleep hardware keys
· Multi-seat management
· Session switch management
· Device access management for users
· Automatic spawning of text logins (gettys) on virtual console
activation and user runtime directory management
要检查会话是否阻止系统挂起,你可以使用loginctl
命令:
列出活动会话:
$ loginctl list-sessions SESSION UID USER SEAT c1 112 lightdm seat0 2 1000 u c2 1000 u seat0
识别远程会话:
$ loginctl session-status 2 Since: lun. 2014-09-08 10:21:22 CEST; 2h 32min ago Leader: 2283 (sshd) Remote: sylvain-thinkpad-t430s.home Service: sshd; type tty; class user State: active Unit: session-2.scope