1
0
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:
Kelly Brazil
2021-01-05 12:29:29 -08:00
parent d8b5d6c66c
commit 7ac621e4c9
3 changed files with 36 additions and 6 deletions

View File

@ -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

View File

@ -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,6 +193,18 @@ def parse(data, raw=False, quiet=False):
output_line['user'] = linedata[0]
output_line['tty'] = linedata[1]
output_line['hostname'] = linedata[2]
# 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['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:

View 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