about summary refs log tree commit diff stats
path: root/bin/weekconns.py
blob: fb152e6bfd0aea3e76f426f3cd73a01e1421ca2f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/local/bin/python3 -I

from sys import exit
import subprocess

def weekconns():
    try:
        conntable = open("/var/www/htdocs/table.weekconns", "w")
    except:
        print("Can't access connected user table. Who are you?")
        exit(0)

    weekconns = list(set(subprocess.check_output("last | grep tty | awk '{print $1}'; exit 0", stderr=subprocess.STDOUT,shell=True).decode().strip()))
    conntable.write(str(len(weekconns)))
    conntable.close()

if __name__ == '__main__':
    weekconns()