blob: 3e5f84d3e06f629d3947c6c69ffc1ef71f251a21 (
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
26
|
#!/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 {}
print("source: /tmp/ssh_sessions.json")
read_data()
|