mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-17 01:32:37 +02:00
add -F support
This commit is contained in:
@ -2,6 +2,12 @@
|
||||
# jc.parsers.last
|
||||
jc - JSON CLI output utility `last` and `lastb` command output parser
|
||||
|
||||
Supports:
|
||||
- `last`
|
||||
- `last -F`
|
||||
- `lastb`
|
||||
- `lastb -F`
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ last | jc --last
|
||||
|
@ -1,5 +1,11 @@
|
||||
"""jc - JSON CLI output utility `last` and `lastb` command output parser
|
||||
|
||||
Supports:
|
||||
- `last`
|
||||
- `last -F`
|
||||
- `lastb`
|
||||
- `lastb -F`
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ last | jc --last
|
||||
@ -81,7 +87,7 @@ import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.3'
|
||||
version = '1.4'
|
||||
description = 'last and lastb command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
@ -187,13 +193,25 @@ def parse(data, raw=False, quiet=False):
|
||||
output_line['user'] = linedata[0]
|
||||
output_line['tty'] = linedata[1]
|
||||
output_line['hostname'] = linedata[2]
|
||||
output_line['login'] = ' '.join(linedata[3:7])
|
||||
|
||||
if len(linedata) > 8:
|
||||
output_line['logout'] = linedata[8]
|
||||
# last -F support
|
||||
if re.match(r'\d\d:\d\d:\d\d \d\d\d\d', ' '.join(linedata[6:8])):
|
||||
output_line['login'] = ' '.join(linedata[3:8])
|
||||
|
||||
if len(linedata) > 9:
|
||||
output_line['duration'] = linedata[9].replace('(', '').replace(')', '')
|
||||
if len(linedata) > 9:
|
||||
output_line['logout'] = ' '.join(linedata[9:14])
|
||||
|
||||
if len(linedata) > 14:
|
||||
output_line['duration'] = linedata[14].replace('(', '').replace(')', '')
|
||||
|
||||
else:
|
||||
output_line['login'] = ' '.join(linedata[3:7])
|
||||
|
||||
if len(linedata) > 8:
|
||||
output_line['logout'] = linedata[8]
|
||||
|
||||
if len(linedata) > 9:
|
||||
output_line['duration'] = linedata[9].replace('(', '').replace(')', '')
|
||||
|
||||
raw_output.append(output_line)
|
||||
|
||||
|
6
tests/fixtures/ubuntu-20.04/last-F.out
vendored
Normal file
6
tests/fixtures/ubuntu-20.04/last-F.out
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
kbrazil pts/0 192.168.71.1 Tue Jan 5 20:03:51 2021 still logged in
|
||||
kbrazil pts/0 192.168.71.1 Tue Jan 5 00:17:29 2021 - Tue Jan 5 20:03:47 2021 (19:46)
|
||||
kbrazil tty1 Tue Jan 5 00:08:46 2021 gone - no logout
|
||||
reboot system boot 5.8.0-34-generic Tue Jan 5 00:08:28 2021 still running
|
||||
|
||||
wtmp begins Tue Jan 5 00:08:28 2021
|
Reference in New Issue
Block a user