From 6e2bd1f5053f5244d1294ba5ae2c0ffc047743b6 Mon Sep 17 00:00:00 2001 From: hc Date: Sat, 1 Feb 2025 10:21:49 +0800 Subject: firstcommit --- client_ls.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 client_ls.py (limited to 'client_ls.py') 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 @@ + +#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()) -- cgit v1.2.3-70-g09d2