#!/usr/local/bin/python3 -I # Lists currently connected users for https://tilde.institute/stats # gbmor # 'ps' truncates usernames at 8 characters (called by 'showwhoison' to find mosh users) # so I'm matching the potentially-partial username to a home directory to retrieve # the full username. from sys import exit import subprocess def checkconns(): try: conntable = open("/var/www/htdocs/table.connusers", "w") except: print("Can't access connected user table. Who are you?") exit(0) connusers = sorted(list(subprocess.check_output("/usr/local/bin/showwhoison | sed -n '1!p'; exit 0", stderr=subprocess.STDOUT,shell=True).decode().split("\n"))) conntable.write("\n") if __name__ == '__main__': checkconns()