Как мне автоматически выйти из системы из Ubuntu?

2641
DrorCohen

Так как моя станция Ubuntu была превращена в Многопользовательскую станцию ​​(дети растут), мне нужен способ автоматического выхода из учетных записей после периода бездействия (полный выход из системы, а не только экран блокировки). Как я могу добиться этого в Ubuntu? Я попытался использовать autolog, но вставив строку:

name=* idle=15 grace=60 

не похоже на работу. Другой вариант - преобразовать этот ответ в Ubuntu-совместимый, но мне нужна помощь в том, что нужно изменить ...

4

1 ответ на вопрос

2
DrorCohen

This is how I solved my problem (this will logout an idle user after at least 30 minutes of idle time):

First create a file and put this code in it (you might need to install xprintidle before you start):

#!/bin/bash # Written by cz0 2010, adapted by dror 2013 # Distributed under the terms of the GNU General Public License v2 HALFHOUR=1800000 IDLETIME=`xprintidle` QDBUS="/usr/bin/qdbus" if [ $IDLETIME -gt $HALFHOUR ] then logger timeout of $HALFHOUR expired. idle is $IDLETIME KDEPID=$(ps aux | grep 'startkde' | grep -v 'grep' | awk '') KDEUSER=$(ps u $KDEPID | grep 'startkde' | awk '') # If the DBUS_SESSION_BUS_ADDRESS environment variable is not already set correctly # then set it by finding the environment file for the startkde process in proc and # parsing it to get get the correct setting. if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then ENVIRON_FILE=/proc/$(ps h --ppid $KDEPID -o pid | awk '')/environ CURRENT_DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS $ENVIRON_FILE | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//') export DBUS_SESSION_BUS_ADDRESS=$CURRENT_DBUS_SESSION_BUS_ADDRESS fi $QDBUS org.kde.ksmserver /KSMServer logout 1 0 2 else logger timeout is $HALFHOUR not expired $IDLETIME fi 

Now cp it to /bin/

sudo cp myfile /bin/logoutonidle 

Next make it executavble

sudo chmod +x /bin/logoutonidle 

Next run per the user you want to logout automatically (if needed then run it on every user):

crontab -e 

and add to it the following line (this will make cron check every 15 minutes so worst case is that user will be logged out after ~45 idle time):

*/15 * * * * export DISPLAY=:0 && /bin/logoutonidle 2>&1 

I would like to thank the people in these threads Bryan and Johanns for pointing me in the right direction.

Дополнение, чтобы избежать сообщения об ошибках: CODI = "не удалось открыть дисплей", если ["$ IDLETIME" -eq "$ CODI"]; затем выйти из Klaus-Peter 7 лет назад 1

Похожие вопросы