Last active
June 9, 2020 13:58
-
-
Save sebastiaanfranken/c8a489e2d9608f1a50c7b2eccd31ce25 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python3 | |
import subprocess | |
# Hoeveelheid tijd (in minuten hier) welke een gebruiker inactief mag zijn | |
threshold = 30 | |
# Bepaal welke gebruiker(s) er actief zijn en haal hier de velden uit welke | |
# nodig zijn | |
output = subprocess.run(['w', '-sh'], capture_output=True, text=True).stdout | |
lines = output.split("\n") | |
for line in lines: | |
fields = line.split(' ') | |
fields = [x for x in fields if x] | |
# De laatste regel is leeg en mag genegeerd worden | |
if len(fields) > 0: | |
seat = fields[1] | |
idle = fields[2].replace('m', '') | |
if int(idle.split(':')[0]) > threshold: | |
#subprocess.run(['pkill', '-9', '-t', seat]); | |
print('De gebruiker op seat %s moet uitgelogd worden.' % seat) | |
else: | |
print('Er zijn geen gebruikers die over de drempel van %s minuten heen zijn' % threshold) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment