Skip to content

Commit 467ad60

Browse files
Fix for who output containing process name #663
1 parent 91b3572 commit 467ad60

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

CHANGELOG

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
jc changelog
22

3-
20250904 v1.25.6
3+
20250908 v1.25.6
44
- Add `net-localgroup` Windows command parser
55
- Add `net-user` Windows command parser
66
- Add `route-print` Windows command parser
77
- Add `x509-crl` file parser to support Certificate Revocation List PEM and DER files
8+
- Add `yay` as a magic command for the `pacman` command parser
89
- Fix `bluetoothctl` command parser to support output with the `cable_pairing` attribute
910
- Fix `nmcli` command parser to support blank `team.config` JSON value and `team-port.config` JSON value
1011
- Fix `top` command parsers to correct memory size field parsing. Several new unit
1112
and byte conversion fields have been added
13+
- Fix `who` command parser to support the `process` field on Debian13
1214

1315
20250503 v1.25.5
1416
- Add `amixer` command parser

jc/parsers/who.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"user": string,
2626
"event": string,
2727
"writeable_tty": string,
28+
"process": string,
2829
"tty": string,
2930
"time": string,
3031
"epoch": integer, # [0]
@@ -136,7 +137,7 @@
136137

137138
class info():
138139
"""Provides parser metadata (version, author, etc.)"""
139-
version = '1.8'
140+
version = '1.9'
140141
description = '`who` command parser'
141142
author = 'Kelly Brazil'
142143
author_email = 'kellyjonbrazil@gmail.com'
@@ -254,6 +255,12 @@ def parse(data, raw=False, quiet=False):
254255
raw_output.append(output_line)
255256
continue
256257

258+
# some output contains process name between the username and pts
259+
# pull the process name for use later if we can find it
260+
user_process = None
261+
if re.match(r'^\S+\s+[^ +-]+\s+pts\/\d+\s', line):
262+
user_process = linedata.pop(1)
263+
257264
# user logins
258265
output_line['user'] = linedata.pop(0)
259266

@@ -262,6 +269,9 @@ def parse(data, raw=False, quiet=False):
262269

263270
output_line['tty'] = linedata.pop(0)
264271

272+
if user_process:
273+
output_line['process'] = user_process
274+
265275
# mac
266276
if re.match(r'[JFMASOND][aepuco][nbrynlgptvc]', linedata[0]):
267277
output_line['time'] = ' '.join([linedata.pop(0),

tests/fixtures/debian13/who.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"user":"root","tty":"tty1","time":"Sep 1 12:20","epoch":null},{"user":"frenkye","tty":"pts/4","process":"sshd","time":"Sep 1 12:05","from":"x.x.x.x","epoch":null},{"user":"root","tty":"tty1","time":"Sep 1 12:25","epoch":null},{"user":"frenkye","tty":"pts/4","time":"Sep 1 12:05","from":"x.x.x.x","epoch":null},{"user":"frenkye","tty":"pts/443","process":"kelly","time":"Sep 1 12:05","from":"x.x.x.x","epoch":null}]

tests/fixtures/debian13/who.out

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
root tty1 Sep 1 12:20
2+
frenkye sshd pts/4 Sep 1 12:05 (x.x.x.x)
3+
root tty1 Sep 1 12:25
4+
frenkye pts/4 Sep 1 12:05 (x.x.x.x)
5+
frenkye kelly pts/443 Sep 1 12:05 (x.x.x.x)

tests/test_who.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class MyTests(unittest.TestCase):
3030
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/who-login-screen.out'), 'r', encoding='utf-8') as f:
3131
generic_who_login_screen = f.read()
3232

33+
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/debian13/who.out'), 'r', encoding='utf-8') as f:
34+
debian13_who = f.read()
35+
3336
# output
3437
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/who.json'), 'r', encoding='utf-8') as f:
3538
centos_7_7_who_json = json.loads(f.read())
@@ -52,6 +55,9 @@ class MyTests(unittest.TestCase):
5255
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/who-login-screen.json'), 'r', encoding='utf-8') as f:
5356
generic_who_login_screen_json = json.loads(f.read())
5457

58+
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/debian13/who.json'), 'r', encoding='utf-8') as f:
59+
debian13_who_json = json.loads(f.read())
60+
5561

5662
def test_who_nodata(self):
5763
"""
@@ -101,5 +107,11 @@ def test_who_login_screen(self):
101107
"""
102108
self.assertEqual(jc.parsers.who.parse(self.generic_who_login_screen, quiet=True), self.generic_who_login_screen_json)
103109

110+
def test_who_debian13(self):
111+
"""
112+
Test 'who' on Debian13
113+
"""
114+
self.assertEqual(jc.parsers.who.parse(self.debian13_who, quiet=True), self.debian13_who_json)
115+
104116
if __name__ == '__main__':
105117
unittest.main()

0 commit comments

Comments
 (0)