diff options
| author | hc <hc@email.ch> | 2025-02-01 10:21:49 +0800 |
|---|---|---|
| committer | hc <hc@email.ch> | 2025-02-01 10:21:49 +0800 |
| commit | 6e2bd1f5053f5244d1294ba5ae2c0ffc047743b6 (patch) | |
| tree | fb1d970b1f952eb372a19d51e360e62c64d36ec6 /client_ls.py | |
firstcommit
Diffstat (limited to 'client_ls.py')
| -rw-r--r-- | client_ls.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/client_ls.py b/client_ls.py new file mode 100644 index 0000000..6aa3a7e --- /dev/null +++ b/client_ls.py | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | |||
| 2 | #lists client information | ||
| 3 | |||
| 4 | import fcntl | ||
| 5 | import json | ||
| 6 | import os | ||
| 7 | |||
| 8 | |||
| 9 | def read_data(): | ||
| 10 | try: | ||
| 11 | with open('/tmp/ssh_sessions.json', 'r') as f: | ||
| 12 | # Get shared lock for reading | ||
| 13 | fcntl.flock(f.fileno(), fcntl.LOCK_SH) | ||
| 14 | try: | ||
| 15 | return json.load(f) | ||
| 16 | finally: | ||
| 17 | fcntl.flock(f.fileno(), fcntl.LOCK_UN) | ||
| 18 | except (FileNotFoundError, ValueError): | ||
| 19 | return {} | ||
| 20 | |||
| 21 | print(read_data()) | ||
