summaryrefslogtreecommitdiff
path: root/client_ls.py
blob: 6aa3a7ec5c8b0db074e1bd164606c77062a21315 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

#lists client information

import fcntl
import json
import os


def read_data():
    try:
        with open('/tmp/ssh_sessions.json', 'r') as f:
            # Get shared lock for reading
            fcntl.flock(f.fileno(), fcntl.LOCK_SH)
            try:
                return json.load(f)
            finally:
                fcntl.flock(f.fileno(), fcntl.LOCK_UN)
    except (FileNotFoundError, ValueError):
        return {}

print(read_data())