blob: fdcfc789b9bd7ebe2eb506cbd842828db5fe7104 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#!/usr/bin/env python3
#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:
data = json.load(f)
for pid, info in data.items():
print(info)
return {}
finally:
fcntl.flock(f.fileno(), fcntl.LOCK_UN)
except (FileNotFoundError, ValueError):
print("file /tmp/ssh_sessions.json not found")
return {}
read_data()
|