Created
October 5, 2020 10:39
-
-
Save keiya/4234e7df8fa20ea5af83d5116bbe60ff to your computer and use it in GitHub Desktop.
auto shutdown script when inactive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import pprint | |
from time import sleep | |
INACTIVE_TIME = 30 | |
pp = pprint.PrettyPrinter(indent=4) | |
inactive_count = 0 | |
while True: | |
session_cnt = int(os.popen('w -h | wc -l').read().rstrip()) | |
#pp.pprint(session_cnt) | |
if session_cnt == 0: | |
inactive_count += 1 | |
if inactive_count > INACTIVE_TIME: | |
os.system('/sbin/shutdown -h now') | |
else: | |
inactive_count = 0 | |
sleep(60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment