2019-10-15 15:06:09 -07:00
# JC
2019-10-17 13:04:34 -07:00
JSON CLI output utility
2019-10-15 15:06:09 -07:00
2019-10-22 11:17:21 -07:00
`jc` is used to JSONify the output of many standard linux cli tools for easier parsing in scripts. See the **Parsers** section for supported commands.
2019-10-15 15:06:09 -07:00
2019-10-18 09:57:10 -07:00
This allows further command line processing of output with tools like `jq` simply by piping commands:
```
2019-11-12 11:46:52 -08:00
$ ls -l /usr/bin | jc --ls | jq '.[] | select(.size > 50000000)'
2019-10-18 09:57:10 -07:00
{
2019-11-12 11:46:52 -08:00
"filename": "docker",
"flags": "-rwxr-xr-x",
"links": 1,
2019-10-18 09:57:10 -07:00
"owner": "root",
2019-11-12 11:46:52 -08:00
"group": "root",
"size": 68677120,
"date": "Aug 14 19:41"
2019-10-18 09:57:10 -07:00
}
```
2019-11-28 11:51:54 -08:00
For more information on the motivations for this project, please see my blog post at https://blog.kellybrazil.com/2019/11/26/bringing-the-unix-philosophy-to-the-21st-century/.
2019-10-18 09:57:10 -07:00
2019-10-25 15:39:48 -07:00
The `jc` parsers can also be used as python modules. In this case the output will be a python dictionary instead of JSON:
2019-10-21 14:13:31 -07:00
```
2019-10-22 07:40:42 -07:00
>>> import jc.parsers.ls
2019-10-25 15:39:48 -07:00
>>>
2019-10-22 07:40:42 -07:00
>>> data='''-rwxr-xr-x 1 root wheel 23648 May 3 22:26 cat
... -rwxr-xr-x 1 root wheel 30016 May 3 22:26 chmod
... -rwxr-xr-x 1 root wheel 29024 May 3 22:26 cp
... -rwxr-xr-x 1 root wheel 375824 May 3 22:26 csh
... -rwxr-xr-x 1 root wheel 28608 May 3 22:26 date
... -rwxr-xr-x 1 root wheel 32000 May 3 22:26 dd
... -rwxr-xr-x 1 root wheel 23392 May 3 22:26 df
... -rwxr-xr-x 1 root wheel 18128 May 3 22:26 echo'''
2019-11-12 11:46:52 -08:00
>>>
2019-10-22 07:40:42 -07:00
>>> jc.parsers.ls.parse(data)
2019-11-12 11:49:14 -08:00
[{'filename': 'cat', 'flags': '-rwxr-xr-x', 'links': 1, 'owner': 'root', 'group': 'wheel', 'size': 23648,
'date': 'May 3 22:26'}, {'filename': 'chmod', 'flags': '-rwxr-xr-x', 'links': 1, 'owner': 'root',
'group': 'wheel', 'size': 30016, 'date': 'May 3 22:26'}, {'filename': 'cp', 'flags': '-rwxr-xr-x',
'links': 1, 'owner': 'root', 'group': 'wheel', 'size': 29024, 'date': 'May 3 22:26'}, {'filename': 'csh',
'flags': '-rwxr-xr-x', 'links': 1, 'owner': 'root', 'group': 'wheel', 'size': 375824, 'date': 'May 3
22:26'}, {'filename': 'date', 'flags': '-rwxr-xr-x', 'links': 1, 'owner': 'root', 'group': 'wheel',
'size': 28608, 'date': 'May 3 22:26'}, {'filename': 'dd', 'flags': '-rwxr-xr-x', 'links': 1, 'owner':
'root', 'group': 'wheel', 'size': 32000, 'date': 'May 3 22:26'}, {'filename': 'df', 'flags':
'-rwxr-xr-x', 'links': 1, 'owner': 'root', 'group': 'wheel', 'size': 23392, 'date': 'May 3 22:26'},
{'filename': 'echo', 'flags': '-rwxr-xr-x', 'links': 1, 'owner': 'root', 'group': 'wheel', 'size': 18128,
'date': 'May 3 22:26'}]
2019-10-25 15:39:48 -07:00
```
2019-11-12 07:18:27 -08:00
Two representations of the data are possible. The default representation uses a strict schema per parser and converts known numbers to int/float JSON values. Certain known values of None are converted to JSON Null, known boolean values are converted, and, in some cases, additional semantic context fields are added.
2019-11-14 13:43:07 -08:00
To access the raw, pre-processed JSON, use the `-r` cli option or the `raw=True` function parameter in `parse()` .
2019-11-12 07:18:27 -08:00
Schemas for each parser can be found in the `docs/parsers` folder.
2019-10-21 14:13:31 -07:00
2019-11-14 14:01:04 -08:00
> ***Note:** Due to the introduction of schemas in version `1.5.1` the output of some parsers will be different than in versions `1.1.1` and below. Now that schemas are defined, the output will be stable for future versions. You can still get similar output to prior versions with the `-r` or `raw=true` options. Though the goal is to keep all output stable, raw output is not guaranteed to stay the same in future releases.*
2019-11-12 11:38:50 -08:00
2019-10-17 15:03:32 -07:00
## Installation
```
2019-10-25 16:14:32 -07:00
$ pip3 install --upgrade jc
2019-10-17 15:03:32 -07:00
```
2019-10-15 15:06:09 -07:00
## Usage
2019-10-21 13:47:22 -07:00
```
2019-10-24 17:53:56 -07:00
jc PARSER [OPTIONS]
2019-10-21 13:47:22 -07:00
```
2019-10-17 15:03:32 -07:00
`jc` accepts piped input from `STDIN` and outputs a JSON representation of the previous command's output to `STDOUT` . The JSON output can be compact or pretty formatted.
2019-10-15 15:06:09 -07:00
2019-10-22 11:15:44 -07:00
### Parsers
2019-10-30 13:22:12 -07:00
- `--arp` enables the `arp` parser
2019-12-16 17:50:52 -08:00
- `--crontab` enables the `crontab` file parser
2019-10-22 11:14:19 -07:00
- `--df` enables the `df` parser
2019-10-31 07:27:12 -07:00
- `--dig` enables the `dig` parser
2019-12-16 14:30:06 -08:00
- `--du` enables the `du` parser
2019-10-22 11:14:19 -07:00
- `--env` enables the `env` parser
- `--free` enables the `free` parser
2019-11-15 09:32:12 -08:00
- `--fstab` enables the `/etc/fstab` file parser
2019-10-24 17:09:32 -07:00
- `--history` enables the `history` parser
2019-11-14 21:59:06 -08:00
- `--hosts` enables the `/etc/hosts` file parser
2019-10-15 15:06:09 -07:00
- `--ifconfig` enables the `ifconfig` parser
2019-10-22 16:50:01 -07:00
- `--iptables` enables the `iptables` parser
2019-10-23 14:10:10 -07:00
- `--jobs` enables the `jobs` parser
2019-10-21 17:26:00 -07:00
- `--ls` enables the `ls` parser
2019-10-22 11:55:11 -07:00
- `--lsblk` enables the `lsblk` parser
2019-10-23 18:30:55 -07:00
- `--lsmod` enables the `lsmod` parser
2019-10-23 17:37:25 -07:00
- `--lsof` enables the `lsof` parser
2019-10-22 12:54:41 -07:00
- `--mount` enables the `mount` parser
2019-10-15 15:06:09 -07:00
- `--netstat` enables the `netstat` parser
2019-12-16 18:36:13 -08:00
- `--pip-list` enables the `pip list` parser
2019-10-18 13:34:28 -07:00
- `--ps` enables the `ps` parser
2019-10-18 14:18:34 -07:00
- `--route` enables the `route` parser
2019-11-12 18:51:21 -08:00
- `--ss` enables the `ss` parser
2019-11-14 16:31:52 -08:00
- `--stat` enables the `stat` parser
2019-11-15 11:58:17 -08:00
- `--systemctl` enables the `systemctl` parser
2019-11-15 19:18:31 -08:00
- `--systemctl-lj` enables the `systemctl list-jobs` parser
- `--systemctl-ls` enables the `systemctl list-sockets` parser
- `--systemctl-luf` enables the `systemctl list-unit-files` parser
2019-10-22 13:28:15 -07:00
- `--uname` enables the `uname -a` parser
2019-10-24 17:09:32 -07:00
- `--uptime` enables the `uptime` parser
2019-10-24 16:06:55 -07:00
- `--w` enables the `w` parser
2019-10-15 15:06:09 -07:00
2019-10-22 11:15:44 -07:00
### Options
2019-12-14 23:27:56 -08:00
- `-a` about `jc` . Prints information about `jc` and the parsers (in JSON, of course!)
2019-11-12 07:18:27 -08:00
- `-d` debug mode. Prints trace messages if parsing issues encountered
2019-11-04 12:50:37 -08:00
- `-p` pretty format the JSON output
2019-11-12 07:18:27 -08:00
- `-q` quiet mode. Suppresses warning messages
2019-11-04 12:50:37 -08:00
- `-r` raw output. Provides a more literal JSON output with all values as text and no additional sematic processing
2019-10-15 15:06:09 -07:00
## Examples
2019-10-30 13:22:12 -07:00
### arp
```
$ arp | jc --arp -p
[
{
"address": "gateway",
"hwtype": "ether",
"hwaddress": "00:50:56:f7:4a:fc",
"flags_mask": "C",
"iface": "ens33"
},
2019-10-30 13:52:31 -07:00
{
"address": "192.168.71.1",
"hwtype": "ether",
"hwaddress": "00:50:56:c0:00:08",
"flags_mask": "C",
"iface": "ens33"
},
2019-10-30 13:22:12 -07:00
{
"address": "192.168.71.254",
"hwtype": "ether",
"hwaddress": "00:50:56:fe:7a:b4",
"flags_mask": "C",
"iface": "ens33"
}
]
```
2019-10-30 13:52:31 -07:00
```
$ arp -a | jc --arp -p
[
{
2019-11-12 13:05:19 -08:00
"name": null,
2019-10-30 13:52:31 -07:00
"address": "192.168.71.1",
"hwtype": "ether",
"hwaddress": "00:50:56:c0:00:08",
"iface": "ens33"
},
{
2019-11-12 13:05:19 -08:00
"name": null,
2019-10-30 13:52:31 -07:00
"address": "192.168.71.254",
"hwtype": "ether",
"hwaddress": "00:50:56:fe:7a:b4",
"iface": "ens33"
},
{
"name": "_gateway",
"address": "192.168.71.2",
"hwtype": "ether",
"hwaddress": "00:50:56:f7:4a:fc",
"iface": "ens33"
}
]
```
2019-12-16 17:50:52 -08:00
### crontab
```
$ crontab | jc --crontab -p
{
"variables": [
{
"name": "MAILTO",
"value": "root"
},
{
"name": "PATH",
"value": "/sbin:/bin:/usr/sbin:/usr/bin"
},
{
"name": "SHELL",
"value": "/bin/bash"
}
],
"schedule": [
{
"minute": [
"5"
],
"hour": [
"10-11",
"22"
],
"day_of_month": [
"*"
],
"month": [
"*"
],
"day_of_week": [
"*"
],
"command": "/var/www/devdaily.com/bin/mk-new-links.php"
},
{
"minute": [
"30"
],
"hour": [
"4/2"
],
"day_of_month": [
"*"
],
"month": [
"*"
],
"day_of_week": [
"*"
],
"command": "/var/www/devdaily.com/bin/create-all-backups.sh"
},
{
"occurrence": "yearly",
"command": "/home/maverick/bin/annual-maintenance"
},
{
"occurrence": "reboot",
"command": "/home/cleanup"
},
{
"occurrence": "monthly",
"command": "/home/maverick/bin/tape-backup"
}
]
}
```
2019-10-22 11:10:11 -07:00
### df
```
$ df | jc --df -p
[
{
2019-11-12 13:05:19 -08:00
"filesystem": "devtmpfs",
2019-12-11 16:39:30 -08:00
"1k_blocks": 1918816,
2019-11-12 13:05:19 -08:00
"used": 0,
"available": 1918816,
"use_percent": 0,
"mounted_on": "/dev"
2019-10-22 11:10:11 -07:00
},
{
2019-10-25 14:58:15 -07:00
"filesystem": "tmpfs",
2019-12-11 16:39:30 -08:00
"1k_blocks": 1930664,
2019-11-12 13:05:19 -08:00
"used": 0,
"available": 1930664,
"use_percent": 0,
"mounted_on": "/dev/shm"
2019-10-22 17:24:56 -07:00
},
...
2019-10-22 11:10:11 -07:00
]
```
2019-10-31 07:27:12 -07:00
### dig
```
$ dig cnn.com www.cnn.com @205 .251.194.64 | jc --dig -p
[
{
2019-11-12 07:18:27 -08:00
"id": 5509,
2019-10-31 07:27:12 -07:00
"opcode": "QUERY",
"status": "NOERROR",
2019-11-12 07:18:27 -08:00
"flags": [
"qr",
"rd",
"ra"
],
"query_num": 1,
"answer_num": 4,
"authority_num": 0,
"additional_num": 1,
2019-10-31 07:27:12 -07:00
"question": {
"name": "cnn.com.",
"class": "IN",
"type": "A"
},
"answer": [
{
"name": "cnn.com.",
"class": "IN",
"type": "A",
2019-11-12 07:18:27 -08:00
"ttl": 60,
"data": "151.101.129.67"
2019-10-31 07:27:12 -07:00
},
{
"name": "cnn.com.",
"class": "IN",
"type": "A",
2019-11-12 07:18:27 -08:00
"ttl": 60,
"data": "151.101.193.67"
2019-10-31 07:27:12 -07:00
},
{
"name": "cnn.com.",
"class": "IN",
"type": "A",
2019-11-12 07:18:27 -08:00
"ttl": 60,
"data": "151.101.1.67"
2019-10-31 07:27:12 -07:00
},
{
"name": "cnn.com.",
"class": "IN",
"type": "A",
2019-11-12 07:18:27 -08:00
"ttl": 60,
2019-10-31 07:27:12 -07:00
"data": "151.101.65.67"
}
],
2019-11-12 07:18:27 -08:00
"query_time": 28,
"server": "2600",
"when": "Tue Nov 12 07:13:03 PST 2019",
"rcvd": 100
2019-10-31 07:27:12 -07:00
},
{
2019-11-12 07:18:27 -08:00
"id": 62696,
2019-10-31 07:27:12 -07:00
"opcode": "QUERY",
"status": "NOERROR",
2019-11-12 07:18:27 -08:00
"flags": [
"qr",
"aa",
"rd"
],
"query_num": 1,
"answer_num": 1,
"authority_num": 4,
"additional_num": 1,
2019-10-31 07:27:12 -07:00
"question": {
"name": "www.cnn.com.",
"class": "IN",
"type": "A"
},
"answer": [
{
"name": "www.cnn.com.",
"class": "IN",
"type": "CNAME",
2019-11-12 07:18:27 -08:00
"ttl": 300,
2019-10-31 07:27:12 -07:00
"data": "turner-tls.map.fastly.net."
}
],
"authority": [
{
"name": "cnn.com.",
"class": "IN",
"type": "NS",
2019-11-12 07:18:27 -08:00
"ttl": 3600,
2019-10-31 07:27:12 -07:00
"data": "ns-1086.awsdns-07.org."
},
{
"name": "cnn.com.",
"class": "IN",
"type": "NS",
2019-11-12 07:18:27 -08:00
"ttl": 3600,
2019-10-31 07:27:12 -07:00
"data": "ns-1630.awsdns-11.co.uk."
},
{
"name": "cnn.com.",
"class": "IN",
"type": "NS",
2019-11-12 07:18:27 -08:00
"ttl": 3600,
2019-10-31 07:27:12 -07:00
"data": "ns-47.awsdns-05.com."
},
{
"name": "cnn.com.",
"class": "IN",
"type": "NS",
2019-11-12 07:18:27 -08:00
"ttl": 3600,
2019-10-31 07:27:12 -07:00
"data": "ns-576.awsdns-08.net."
}
],
2019-11-12 07:18:27 -08:00
"query_time": 29,
2019-10-31 07:27:12 -07:00
"server": "205.251.194.64#53 (205.251.194.64)",
2019-11-12 07:18:27 -08:00
"when": "Tue Nov 12 07:13:03 PST 2019",
"rcvd": 212
2019-10-31 07:27:12 -07:00
}
]
```
```
$ dig -x 1.1.1.1 | jc --dig -p
[
{
2019-11-12 07:18:27 -08:00
"id": 50324,
2019-10-31 07:27:12 -07:00
"opcode": "QUERY",
"status": "NOERROR",
2019-11-12 07:18:27 -08:00
"flags": [
"qr",
"rd",
"ra"
],
"query_num": 1,
"answer_num": 1,
"authority_num": 0,
"additional_num": 1,
2019-10-31 07:27:12 -07:00
"question": {
"name": "1.1.1.1.in-addr.arpa.",
"class": "IN",
"type": "PTR"
},
"answer": [
{
2019-11-12 07:18:27 -08:00
"name": "1.1.1.1.in-addr.arpa.",
2019-10-31 07:27:12 -07:00
"class": "IN",
"type": "PTR",
2019-11-12 07:18:27 -08:00
"ttl": 1634,
2019-10-31 07:27:12 -07:00
"data": "one.one.one.one."
}
],
2019-11-12 07:18:27 -08:00
"query_time": 36,
"server": "2600",
"when": "Tue Nov 12 07:13:49 PST 2019",
"rcvd": 78
2019-10-31 07:27:12 -07:00
}
]
```
2019-12-16 14:31:21 -08:00
### du
```
$ du /usr | jc --du -p
[
{
"size": 104608,
"name": "/usr/bin"
},
{
"size": 56,
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/_CodeSignature"
},
{
"size": 0,
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/Resources/Firmware/usr/local/standalone"
},
{
"size": 0,
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/Resources/Firmware/usr/local"
},
{
"size": 0,
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/Resources/Firmware/usr"
},
{
"size": 1008,
"name": "/usr/standalone/firmware/iBridge1_1Customer.bundle/Contents/Resources/Firmware/dfu"
},
...
]
```
2019-10-22 11:10:11 -07:00
### env
```
$ env | jc --env -p
2019-11-12 13:05:19 -08:00
[
{
"name": "XDG_SESSION_ID",
"value": "1"
},
{
"name": "HOSTNAME",
"value": "localhost.localdomain"
},
{
"name": "TERM",
"value": "vt220"
},
{
"name": "SHELL",
"value": "/bin/bash"
},
{
"name": "HISTSIZE",
"value": "1000"
},
...
]
2019-10-22 11:10:11 -07:00
```
2019-10-24 17:09:32 -07:00
### free
```
$ free | jc --free -p
[
{
"type": "Mem",
2019-11-12 13:05:19 -08:00
"total": 3861340,
"used": 220508,
"free": 3381972,
"shared": 11800,
"buff_cache": 258860,
"available": 3397784
2019-10-24 17:09:32 -07:00
},
{
"type": "Swap",
2019-11-12 13:05:19 -08:00
"total": 2097148,
"used": 0,
"free": 2097148
2019-10-24 17:09:32 -07:00
}
]
```
2019-11-15 09:29:54 -08:00
### /etc/fstab
```
$ cat /etc/fstab | jc --fstab -p
[
{
"fs_spec": "/dev/mapper/centos-root",
"fs_file": "/",
"fs_vfstype": "xfs",
"fs_mntops": "defaults",
"fs_freq": 0,
"fs_passno": 0
},
{
"fs_spec": "UUID=05d927bb-5875-49e3-ada1-7f46cb31c932",
"fs_file": "/boot",
"fs_vfstype": "xfs",
"fs_mntops": "defaults",
"fs_freq": 0,
"fs_passno": 0
},
{
"fs_spec": "/dev/mapper/centos-swap",
"fs_file": "swap",
"fs_vfstype": "swap",
"fs_mntops": "defaults",
"fs_freq": 0,
"fs_passno": 0
}
]
```
2019-10-24 17:09:32 -07:00
### history
```
$ history | jc --history -p
2019-11-12 13:05:19 -08:00
[
{
"line": "118",
"command": "sleep 100"
},
{
"line": "119",
"command": "ls /bin"
},
{
"line": "120",
"command": "echo \"hello\""
},
{
"line": "121",
"command": "docker images"
},
2019-10-24 17:09:32 -07:00
...
2019-11-12 13:05:19 -08:00
]
2019-10-24 17:09:32 -07:00
```
2019-11-14 21:59:06 -08:00
### /etc/hosts
```
$ cat /etc/hosts | jc --hosts -p
[
{
"ip": "127.0.0.1",
"hostname": [
"localhost"
]
},
{
"ip": "127.0.1.1",
"hostname": [
"root-ubuntu"
]
},
{
"ip": "::1",
"hostname": [
"ip6-localhost",
"ip6-loopback"
]
},
{
"ip": "fe00::0",
"hostname": [
"ip6-localnet"
]
},
{
"ip": "ff00::0",
"hostname": [
"ip6-mcastprefix"
]
},
{
"ip": "ff02::1",
"hostname": [
"ip6-allnodes"
]
},
{
"ip": "ff02::2",
"hostname": [
"ip6-allrouters"
]
}
]
```
2019-10-18 09:57:10 -07:00
### ifconfig
2019-10-17 15:03:32 -07:00
```
2019-10-15 15:32:23 -07:00
$ ifconfig | jc --ifconfig -p
[
{
"name": "ens33",
2019-11-12 13:05:19 -08:00
"flags": 4163,
2019-12-06 11:44:57 -08:00
"state": [
"UP",
"BROADCAST",
"RUNNING",
"MULTICAST"
],
2019-11-12 13:05:19 -08:00
"mtu": 1500,
2019-12-06 11:44:57 -08:00
"ipv4_addr": "192.168.71.137",
2019-10-15 15:32:23 -07:00
"ipv4_mask": "255.255.255.0",
"ipv4_bcast": "192.168.71.255",
"ipv6_addr": "fe80::c1cb:715d:bc3e:b8a0",
2019-11-12 13:05:19 -08:00
"ipv6_mask": 64,
2019-12-06 11:44:57 -08:00
"ipv6_scope": "0x20",
2019-10-15 15:32:23 -07:00
"mac_addr": "00:0c:29:3b:58:0e",
"type": "Ethernet",
2019-12-06 11:44:57 -08:00
"rx_packets": 8061,
"rx_bytes": 1514413,
2019-11-12 13:05:19 -08:00
"rx_errors": 0,
"rx_dropped": 0,
"rx_overruns": 0,
"rx_frame": 0,
2019-12-06 11:44:57 -08:00
"tx_packets": 4502,
"tx_bytes": 866622,
2019-11-12 13:05:19 -08:00
"tx_errors": 0,
"tx_dropped": 0,
"tx_overruns": 0,
"tx_carrier": 0,
"tx_collisions": 0,
2019-10-15 15:32:23 -07:00
"metric": null
},
{
"name": "lo",
2019-11-12 13:05:19 -08:00
"flags": 73,
2019-12-06 11:44:57 -08:00
"state": [
"UP",
"LOOPBACK",
"RUNNING"
],
2019-11-12 13:05:19 -08:00
"mtu": 65536,
2019-10-15 15:32:23 -07:00
"ipv4_addr": "127.0.0.1",
"ipv4_mask": "255.0.0.0",
"ipv4_bcast": null,
"ipv6_addr": "::1",
2019-11-12 13:05:19 -08:00
"ipv6_mask": 128,
2019-12-06 11:44:57 -08:00
"ipv6_scope": "0x10",
2019-10-15 15:32:23 -07:00
"mac_addr": null,
"type": "Local Loopback",
2019-12-06 11:44:57 -08:00
"rx_packets": 73,
"rx_bytes": 6009,
2019-11-12 13:05:19 -08:00
"rx_errors": 0,
"rx_dropped": 0,
"rx_overruns": 0,
"rx_frame": 0,
2019-12-06 11:44:57 -08:00
"tx_packets": 73,
"tx_bytes": 6009,
2019-11-12 13:05:19 -08:00
"tx_errors": 0,
"tx_dropped": 0,
"tx_overruns": 0,
"tx_carrier": 0,
"tx_collisions": 0,
2019-10-15 15:32:23 -07:00
"metric": null
}
]
2019-10-17 15:03:32 -07:00
```
2019-10-22 16:40:27 -07:00
### iptables
```
2019-11-12 13:05:19 -08:00
$ sudo iptables --line-numbers -v -L -t nat | jc --iptables -p
2019-10-22 16:40:27 -07:00
[
{
"chain": "PREROUTING",
"rules": [
{
2019-11-12 13:05:19 -08:00
"num": 1,
"pkts": 2183,
"bytes": 186000,
2019-10-22 16:40:27 -07:00
"target": "PREROUTING_direct",
"prot": "all",
2019-11-12 13:05:19 -08:00
"opt": null,
"in": "any",
"out": "any",
2019-10-22 16:40:27 -07:00
"source": "anywhere",
"destination": "anywhere"
},
{
2019-11-12 13:05:19 -08:00
"num": 2,
"pkts": 2183,
"bytes": 186000,
2019-10-22 16:40:27 -07:00
"target": "PREROUTING_ZONES_SOURCE",
"prot": "all",
2019-11-12 13:05:19 -08:00
"opt": null,
"in": "any",
"out": "any",
2019-10-22 16:40:27 -07:00
"source": "anywhere",
"destination": "anywhere"
},
{
2019-11-12 13:05:19 -08:00
"num": 3,
"pkts": 2183,
"bytes": 186000,
2019-10-22 16:40:27 -07:00
"target": "PREROUTING_ZONES",
"prot": "all",
2019-11-12 13:05:19 -08:00
"opt": null,
"in": "any",
"out": "any",
2019-10-22 16:40:27 -07:00
"source": "anywhere",
"destination": "anywhere"
},
{
2019-11-12 13:05:19 -08:00
"num": 4,
"pkts": 0,
"bytes": 0,
2019-10-22 16:40:27 -07:00
"target": "DOCKER",
"prot": "all",
2019-11-12 13:05:19 -08:00
"opt": null,
"in": "any",
"out": "any",
2019-10-22 16:40:27 -07:00
"source": "anywhere",
"destination": "anywhere",
"options": "ADDRTYPE match dst-type LOCAL"
}
]
},
...
]
```
2019-10-23 14:10:10 -07:00
### jobs
```
$ jobs -l | jc --jobs -p
[
{
2019-11-12 13:05:19 -08:00
"job_number": 1,
"pid": 5283,
2019-10-23 14:10:10 -07:00
"status": "Running",
2019-11-12 13:05:19 -08:00
"command": "sleep 10000 & "
2019-10-23 14:10:10 -07:00
},
{
2019-11-12 13:05:19 -08:00
"job_number": 2,
"pid": 5284,
2019-10-23 14:10:10 -07:00
"status": "Running",
2019-11-12 13:05:19 -08:00
"command": "sleep 10100 & "
2019-10-23 14:10:10 -07:00
},
{
2019-11-12 13:05:19 -08:00
"job_number": 3,
"pid": 5285,
2019-10-23 14:10:10 -07:00
"history": "previous",
"status": "Running",
2019-11-12 13:05:19 -08:00
"command": "sleep 10001 & "
2019-10-23 14:10:10 -07:00
},
{
2019-11-12 13:05:19 -08:00
"job_number": 4,
"pid": 5286,
2019-10-23 14:10:10 -07:00
"history": "current",
"status": "Running",
2019-11-12 13:05:19 -08:00
"command": "sleep 10112 & "
2019-10-23 14:10:10 -07:00
}
]
```
2019-10-21 17:26:00 -07:00
### ls
```
2019-10-25 15:39:48 -07:00
$ ls -l /usr/bin | jc --ls -p
2019-10-21 17:26:00 -07:00
[
{
2019-10-25 15:39:48 -07:00
"filename": "apropos",
"link_to": "whatis",
"flags": "lrwxrwxrwx.",
2019-11-12 13:05:19 -08:00
"links": 1,
2019-10-21 17:26:00 -07:00
"owner": "root",
2019-10-25 15:39:48 -07:00
"group": "root",
2019-11-12 13:05:19 -08:00
"size": 6,
2019-10-25 15:39:48 -07:00
"date": "Aug 15 10:53"
2019-10-21 17:26:00 -07:00
},
{
2019-11-12 13:05:19 -08:00
"filename": "ar",
2019-10-25 15:39:48 -07:00
"flags": "-rwxr-xr-x.",
2019-11-12 13:05:19 -08:00
"links": 1,
2019-10-21 17:26:00 -07:00
"owner": "root",
2019-10-25 15:39:48 -07:00
"group": "root",
2019-11-12 13:05:19 -08:00
"size": 62744,
"date": "Aug 8 16:14"
2019-10-25 15:39:48 -07:00
},
{
2019-11-12 13:05:19 -08:00
"filename": "arch",
2019-10-25 15:39:48 -07:00
"flags": "-rwxr-xr-x.",
2019-11-12 13:05:19 -08:00
"links": 1,
2019-10-25 15:39:48 -07:00
"owner": "root",
"group": "root",
2019-11-12 13:05:19 -08:00
"size": 33080,
2019-10-25 15:39:48 -07:00
"date": "Aug 19 23:25"
},
2019-10-21 17:26:00 -07:00
...
]
```
2019-10-22 11:55:11 -07:00
### lsblk
```
$ lsblk | jc --lsblk -p
[
{
2019-10-25 14:58:15 -07:00
"name": "sda",
"maj_min": "8:0",
2019-11-12 13:05:19 -08:00
"rm": false,
2019-10-25 14:58:15 -07:00
"size": "20G",
2019-11-12 13:05:19 -08:00
"ro": false,
"type": "disk",
"mountpoint": null
2019-10-25 14:58:15 -07:00
},
{
"name": "sda1",
"maj_min": "8:1",
2019-11-12 13:05:19 -08:00
"rm": false,
2019-10-25 14:58:15 -07:00
"size": "1G",
2019-11-12 13:05:19 -08:00
"ro": false,
2019-10-25 14:58:15 -07:00
"type": "part",
"mountpoint": "/boot"
2019-10-22 11:55:11 -07:00
},
2019-11-12 13:05:19 -08:00
...
2019-10-22 11:55:11 -07:00
]
```
2019-10-23 18:30:55 -07:00
### lsmod
```
$ lsmod | jc --lsmod -p
[
2019-10-25 14:58:15 -07:00
...
2019-10-23 18:30:55 -07:00
{
2019-11-12 13:05:19 -08:00
"module": "nf_nat",
"size": 26583,
"used": 3,
2019-10-25 14:58:15 -07:00
"by": [
2019-10-23 18:30:55 -07:00
"nf_nat_ipv4",
"nf_nat_ipv6",
2019-11-12 13:05:19 -08:00
"nf_nat_masquerade_ipv4"
2019-10-23 18:30:55 -07:00
]
},
{
2019-11-12 13:05:19 -08:00
"module": "iptable_mangle",
"size": 12695,
"used": 1
2019-10-23 18:30:55 -07:00
},
{
2019-11-12 13:05:19 -08:00
"module": "iptable_security",
"size": 12705,
"used": 1
2019-10-23 18:30:55 -07:00
},
{
2019-11-12 13:05:19 -08:00
"module": "iptable_raw",
"size": 12678,
"used": 1
2019-10-23 18:30:55 -07:00
},
{
2019-11-12 13:05:19 -08:00
"module": "nf_conntrack",
"size": 139224,
"used": 7,
2019-10-25 14:58:15 -07:00
"by": [
2019-11-12 13:05:19 -08:00
"nf_nat",
"nf_nat_ipv4",
"nf_nat_ipv6",
"xt_conntrack",
"nf_nat_masquerade_ipv4",
"nf_conntrack_ipv4",
"nf_conntrack_ipv6"
2019-10-23 18:30:55 -07:00
]
},
...
]
```
2019-10-23 17:37:25 -07:00
### lsof
```
2019-11-12 13:05:19 -08:00
$ sudo lsof | jc --lsof -p
2019-10-23 17:37:25 -07:00
[
{
2019-10-25 14:58:15 -07:00
"command": "systemd",
2019-11-12 13:05:19 -08:00
"pid": 1,
2019-10-25 14:58:15 -07:00
"tid": null,
"user": "root",
"fd": "cwd",
"type": "DIR",
2019-11-12 13:05:19 -08:00
"device": "253,0",
"size_off": 224,
"node": 64,
2019-10-25 14:58:15 -07:00
"name": "/"
2019-10-23 17:37:25 -07:00
},
{
2019-10-25 14:58:15 -07:00
"command": "systemd",
2019-11-12 13:05:19 -08:00
"pid": 1,
2019-10-25 14:58:15 -07:00
"tid": null,
"user": "root",
"fd": "rtd",
"type": "DIR",
2019-11-12 13:05:19 -08:00
"device": "253,0",
"size_off": 224,
"node": 64,
2019-10-25 14:58:15 -07:00
"name": "/"
2019-10-23 17:37:25 -07:00
},
{
2019-10-25 14:58:15 -07:00
"command": "systemd",
2019-11-12 13:05:19 -08:00
"pid": 1,
2019-10-25 14:58:15 -07:00
"tid": null,
"user": "root",
"fd": "txt",
"type": "REG",
2019-11-12 13:05:19 -08:00
"device": "253,0",
"size_off": 1624520,
"node": 50360451,
"name": "/usr/lib/systemd/systemd"
2019-10-23 17:37:25 -07:00
},
...
]
```
2019-10-22 12:54:41 -07:00
### mount
```
$ mount | jc --mount -p
[
{
"filesystem": "sysfs",
"mount_point": "/sys",
"type": "sysfs",
2019-11-12 13:05:19 -08:00
"options": [
2019-10-22 12:54:41 -07:00
"rw",
"nosuid",
"nodev",
"noexec",
"relatime"
]
},
{
"filesystem": "proc",
"mount_point": "/proc",
"type": "proc",
2019-11-12 13:05:19 -08:00
"options": [
2019-10-22 12:54:41 -07:00
"rw",
"nosuid",
"nodev",
"noexec",
"relatime"
]
},
{
"filesystem": "udev",
"mount_point": "/dev",
"type": "devtmpfs",
2019-11-12 13:05:19 -08:00
"options": [
2019-10-22 12:54:41 -07:00
"rw",
"nosuid",
"relatime",
"size=977500k",
"nr_inodes=244375",
"mode=755"
]
},
...
]
```
2019-10-18 09:57:10 -07:00
### netstat
2019-10-17 15:03:32 -07:00
```
2019-11-12 13:05:19 -08:00
$ sudo netstat -apee | jc --netstat -p
2019-10-21 13:47:22 -07:00
[
{
2019-11-12 13:05:19 -08:00
"proto": "tcp",
"recv_q": 0,
"send_q": 0,
"local_address": "localhost",
"foreign_address": "0.0.0.0",
"state": "LISTEN",
"user": "systemd-resolve",
"inode": 26958,
"program_name": "systemd-resolve",
"kind": "network",
"pid": 887,
"local_port": "domain",
"foreign_port": "*",
2019-10-21 18:22:51 -07:00
"transport_protocol": "tcp",
2019-11-12 13:05:19 -08:00
"network_protocol": "ipv4"
2019-10-21 13:47:22 -07:00
},
{
2019-11-12 13:05:19 -08:00
"proto": "tcp",
"recv_q": 0,
"send_q": 0,
"local_address": "0.0.0.0",
"foreign_address": "0.0.0.0",
"state": "LISTEN",
"user": "root",
"inode": 30499,
"program_name": "sshd",
"kind": "network",
"pid": 1186,
"local_port": "ssh",
"foreign_port": "*",
2019-10-21 18:22:51 -07:00
"transport_protocol": "tcp",
2019-11-12 13:05:19 -08:00
"network_protocol": "ipv4"
},
2019-10-21 13:47:22 -07:00
{
2019-11-12 13:05:19 -08:00
"proto": "tcp",
"recv_q": 0,
"send_q": 0,
"local_address": "localhost",
"foreign_address": "localhost",
"state": "ESTABLISHED",
"user": "root",
"inode": 46829,
"program_name": "sshd: root",
"kind": "network",
"pid": 2242,
"local_port": "ssh",
"foreign_port": "52186",
2019-10-21 18:22:51 -07:00
"transport_protocol": "tcp",
2019-10-21 13:47:22 -07:00
"network_protocol": "ipv4",
2019-11-12 13:05:19 -08:00
"foreign_port_num": 52186
2019-10-21 13:47:22 -07:00
},
{
2019-11-12 13:05:19 -08:00
"proto": "tcp",
"recv_q": 0,
"send_q": 0,
"local_address": "localhost",
"foreign_address": "localhost",
"state": "ESTABLISHED",
"user": "root",
"inode": 46828,
"program_name": "ssh",
"kind": "network",
"pid": 2241,
"local_port": "52186",
"foreign_port": "ssh",
2019-10-21 18:22:51 -07:00
"transport_protocol": "tcp",
2019-10-21 13:47:22 -07:00
"network_protocol": "ipv4",
2019-11-12 13:05:19 -08:00
"local_port_num": 52186
},
{
"proto": "tcp6",
"recv_q": 0,
"send_q": 0,
"local_address": "[::]",
"foreign_address": "[::]",
2019-10-21 13:47:22 -07:00
"state": "LISTEN",
2019-11-12 13:05:19 -08:00
"user": "root",
"inode": 30510,
2019-10-21 13:47:22 -07:00
"program_name": "sshd",
2019-11-12 13:05:19 -08:00
"kind": "network",
"pid": 1186,
"local_port": "ssh",
"foreign_port": "*",
"transport_protocol": "tcp",
"network_protocol": "ipv6"
2019-10-21 13:47:22 -07:00
},
{
2019-11-12 13:05:19 -08:00
"proto": "udp",
"recv_q": 0,
"send_q": 0,
"local_address": "localhost",
"foreign_address": "0.0.0.0",
"state": null,
"user": "systemd-resolve",
"inode": 26957,
"program_name": "systemd-resolve",
"kind": "network",
"pid": 887,
"local_port": "domain",
2019-10-21 13:47:22 -07:00
"foreign_port": "*",
2019-11-12 13:05:19 -08:00
"transport_protocol": "udp",
"network_protocol": "ipv4"
2019-10-21 13:47:22 -07:00
},
{
2019-11-12 13:05:19 -08:00
"proto": "raw6",
"recv_q": 0,
"send_q": 0,
"local_address": "[::]",
"foreign_address": "[::]",
"state": "7",
"user": "systemd-network",
"inode": 27001,
"program_name": "systemd-network",
"kind": "network",
"pid": 867,
"local_port": "ipv6-icmp",
2019-10-21 13:47:22 -07:00
"foreign_port": "*",
2019-11-12 13:05:19 -08:00
"transport_protocol": null,
"network_protocol": "ipv6"
},
{
"proto": "unix",
"refcnt": 2,
"flags": null,
"type": "DGRAM",
"state": null,
"inode": 33322,
"program_name": "systemd",
"path": "/run/user/1000/systemd/notify",
"kind": "socket",
"pid": 1607
},
{
"proto": "unix",
"refcnt": 2,
"flags": "ACC",
"type": "SEQPACKET",
"state": "LISTENING",
"inode": 20835,
"program_name": "init",
"path": "/run/udev/control",
"kind": "socket",
"pid": 1
2019-10-25 15:39:48 -07:00
},
...
2019-10-21 13:47:22 -07:00
]
2019-12-16 18:36:13 -08:00
```
### pip list
```
$ pip list | jc --pip-list -p
[
{
"package": "ansible",
"version": "2.8.5"
},
{
"package": "antlr4-python3-runtime",
"version": "4.7.2"
},
{
"package": "asn1crypto",
"version": "0.24.0"
},
...
]
2019-10-15 15:06:09 -07:00
```
2019-10-18 13:34:28 -07:00
### ps
```
$ ps -ef | jc --ps -p
[
{
2019-10-25 14:58:15 -07:00
"uid": "root",
2019-11-12 13:05:19 -08:00
"pid": 1,
"ppid": 0,
"c": 0,
"stime": "Nov01",
"tty": null,
"time": "00:00:11",
"cmd": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22"
2019-10-18 13:34:28 -07:00
},
{
2019-10-25 14:58:15 -07:00
"uid": "root",
2019-11-12 13:05:19 -08:00
"pid": 2,
"ppid": 0,
"c": 0,
"stime": "Nov01",
"tty": null,
2019-10-25 14:58:15 -07:00
"time": "00:00:00",
2019-11-12 13:05:19 -08:00
"cmd": "[kthreadd]"
2019-10-18 13:34:28 -07:00
},
{
2019-10-25 14:58:15 -07:00
"uid": "root",
2019-11-12 13:05:19 -08:00
"pid": 4,
"ppid": 2,
"c": 0,
"stime": "Nov01",
"tty": null,
2019-10-25 14:58:15 -07:00
"time": "00:00:00",
2019-11-12 13:05:19 -08:00
"cmd": "[kworker/0:0H]"
2019-10-18 13:34:28 -07:00
},
2019-11-12 13:05:19 -08:00
...
]
```
```
$ ps axu | jc --ps -p
[
2019-10-18 13:34:28 -07:00
{
2019-11-12 13:05:19 -08:00
"user": "root",
"pid": 1,
2019-11-12 15:05:21 -08:00
"cpu_percent": 0.0,
"mem_percent": 0.1,
"vsz": 128072,
"rss": 6784,
2019-11-12 13:05:19 -08:00
"tty": null,
"stat": "Ss",
"start": "Nov09",
2019-11-12 15:05:21 -08:00
"time": "0:08",
2019-11-12 13:05:19 -08:00
"command": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22"
2019-10-25 14:58:15 -07:00
},
{
2019-11-12 13:05:19 -08:00
"user": "root",
"pid": 2,
2019-11-12 15:05:21 -08:00
"cpu_percent": 0.0,
"mem_percent": 0.0,
"vsz": 0,
"rss": 0,
2019-11-12 13:05:19 -08:00
"tty": null,
"stat": "S",
"start": "Nov09",
"time": "0:00",
"command": "[kthreadd]"
},
{
"user": "root",
"pid": 4,
2019-11-12 15:05:21 -08:00
"cpu_percent": 0.0,
"mem_percent": 0.0,
"vsz": 0,
"rss": 0,
2019-11-12 13:05:19 -08:00
"tty": null,
"stat": "S< ",
"start": "Nov09",
"time": "0:00",
"command": "[kworker/0:0H]"
2019-10-18 13:34:28 -07:00
},
...
]
```
2019-10-18 14:18:34 -07:00
### route
```
2019-11-12 13:05:19 -08:00
$ route -ee | jc --route -p
2019-10-18 14:18:34 -07:00
[
{
2019-10-25 14:58:15 -07:00
"destination": "default",
"gateway": "gateway",
"genmask": "0.0.0.0",
"flags": "UG",
2019-11-12 13:05:19 -08:00
"metric": 100,
"ref": 0,
"use": 0,
"iface": "ens33",
"mss": 0,
"window": 0,
"irtt": 0
2019-10-18 14:18:34 -07:00
},
{
2019-10-25 14:58:15 -07:00
"destination": "172.17.0.0",
"gateway": "0.0.0.0",
"genmask": "255.255.0.0",
"flags": "U",
2019-11-12 13:05:19 -08:00
"metric": 0,
"ref": 0,
"use": 0,
"iface": "docker",
"mss": 0,
"window": 0,
"irtt": 0
2019-10-18 14:18:34 -07:00
},
{
2019-10-25 14:58:15 -07:00
"destination": "192.168.71.0",
"gateway": "0.0.0.0",
"genmask": "255.255.255.0",
"flags": "U",
2019-11-12 13:05:19 -08:00
"metric": 100,
"ref": 0,
"use": 0,
"iface": "ens33",
"mss": 0,
"window": 0,
"irtt": 0
2019-10-18 14:18:34 -07:00
}
]
```
2019-11-12 18:51:21 -08:00
### ss
```
$ sudo ss -a | jc --ss -p
[
{
"netid": "nl",
"state": "UNCONN",
"recv_q": 0,
"send_q": 0,
2019-11-14 09:46:10 -08:00
"peer_address": "*",
"channel": "rtnl:kernel"
2019-11-12 18:51:21 -08:00
},
{
"netid": "nl",
"state": "UNCONN",
"recv_q": 0,
"send_q": 0,
2019-11-14 09:46:10 -08:00
"peer_address": "*",
"pid": 893,
"channel": "rtnl:systemd-resolve"
2019-11-12 18:51:21 -08:00
},
2019-11-14 09:46:10 -08:00
...
2019-11-12 18:51:21 -08:00
{
2019-11-14 09:46:10 -08:00
"netid": "p_raw",
"state": "UNCONN",
"recv_q": 0,
"send_q": 0,
"peer_address": "*",
"link_layer": "LLDP",
"interface": "ens33"
},
{
"netid": "u_dgr",
2019-11-12 18:51:21 -08:00
"state": "UNCONN",
"recv_q": 0,
"send_q": 0,
2019-11-14 09:46:10 -08:00
"local_port": "93066",
"peer_address": "*",
"peer_port": "0",
"path": "/run/user/1000/systemd/notify"
},
{
"netid": "u_seq",
"state": "LISTEN",
"recv_q": 0,
"send_q": 128,
"local_port": "20699",
"peer_address": "*",
"peer_port": "0",
"path": "/run/udev/control"
2019-11-12 18:51:21 -08:00
},
...
2019-11-14 09:46:10 -08:00
{
"netid": "icmp6",
"state": "UNCONN",
"recv_q": 0,
"send_q": 0,
"local_address": "*",
"local_port": "ipv6-icmp",
"peer_address": "*",
"peer_port": "*",
"interface": "ens33"
},
{
"netid": "udp",
"state": "UNCONN",
"recv_q": 0,
"send_q": 0,
"local_address": "127.0.0.53",
"local_port": "domain",
"peer_address": "0.0.0.0",
"peer_port": "*",
"interface": "lo"
},
2019-11-12 18:51:21 -08:00
{
"netid": "tcp",
"state": "LISTEN",
"recv_q": 0,
"send_q": 128,
2019-11-14 09:46:10 -08:00
"local_address": "127.0.0.53",
"local_port": "domain",
2019-11-12 18:51:21 -08:00
"peer_address": "0.0.0.0",
"peer_port": "*",
"interface": "lo"
},
2019-11-14 09:46:10 -08:00
{
"netid": "tcp",
"state": "LISTEN",
"recv_q": 0,
"send_q": 128,
"local_address": "0.0.0.0",
"local_port": "ssh",
"peer_address": "0.0.0.0",
"peer_port": "*"
},
2019-11-12 18:51:21 -08:00
{
"netid": "tcp",
"state": "LISTEN",
"recv_q": 0,
"send_q": 128,
"local_address": "[::]",
"local_port": "ssh",
"peer_address": "[::]",
"peer_port": "*"
},
{
"netid": "v_str",
"state": "ESTAB",
"recv_q": 0,
"send_q": 0,
"local_address": "999900439",
"local_port": "1023",
"peer_address": "0",
"peer_port": "976",
"local_port_num": 1023,
"peer_port_num": 976
}
]
```
2019-11-14 16:31:52 -08:00
### stat
```
$ stat /bin/* | jc --stat -p
[
{
"file": "/bin/bash",
"size": 1113504,
"blocks": 2176,
"io_blocks": 4096,
"type": "regular file",
"device": "802h/2050d",
"inode": 131099,
"links": 1,
"access": "0755",
"flags": "-rwxr-xr-x",
"uid": 0,
"user": "root",
"gid": 0,
"group": "root",
"access_time": "2019-11-14 08:18:03.509681766 +0000",
"modify_time": "2019-06-06 22:28:15.000000000 +0000",
"change_time": "2019-08-12 17:21:29.521945390 +0000",
2019-11-14 17:36:29 -08:00
"birth_time": null
2019-11-14 16:31:52 -08:00
},
{
"file": "/bin/btrfs",
"size": 716464,
"blocks": 1400,
"io_blocks": 4096,
"type": "regular file",
"device": "802h/2050d",
"inode": 131100,
"links": 1,
"access": "0755",
"flags": "-rwxr-xr-x",
"uid": 0,
"user": "root",
"gid": 0,
"group": "root",
"access_time": "2019-11-14 08:18:28.990834276 +0000",
"modify_time": "2018-03-12 23:04:27.000000000 +0000",
"change_time": "2019-08-12 17:21:29.545944399 +0000",
2019-11-14 17:36:29 -08:00
"birth_time": null
2019-11-14 16:31:52 -08:00
},
...
]
```
2019-11-15 11:58:17 -08:00
### systemctl
```
$ systemctl -a | jc --systemctl -p
[
{
"unit": "proc-sys-fs-binfmt_misc.automount",
"load": "loaded",
"active": "active",
"sub": "waiting",
"description": "Arbitrary Executable File Formats File System Automount Point"
},
{
"unit": "dev-block-8:2.device",
"load": "loaded",
"active": "active",
"sub": "plugged",
"description": "LVM PV 3klkIj-w1qk-DkJi-0XBJ-y3o7-i2Ac-vHqWBM on /dev/sda2 2"
},
{
"unit": "dev-cdrom.device",
"load": "loaded",
"active": "active",
"sub": "plugged",
"description": "VMware_Virtual_IDE_CDROM_Drive"
},
...
]
```
2019-11-15 19:18:31 -08:00
### systemctl list-jobs
```
$ systemctl list-jobs| jc --systemctl-lj -p
[
{
"job": 3543,
"unit": "nginxAfterGlusterfs.service",
"type": "start",
"state": "waiting"
},
{
"job": 3545,
"unit": "glusterReadyForLocalhostMount.service",
"type": "start",
"state": "running"
},
{
"job": 3506,
"unit": "nginx.service",
"type": "start",
"state": "waiting"
}
]
```
### systemctl list-sockets
```
$ systemctl list-sockets | jc --systemctl-ls -p
[
{
"listen": "/dev/log",
"unit": "systemd-journald.socket",
"activates": "systemd-journald.service"
},
{
"listen": "/run/dbus/system_bus_socket",
"unit": "dbus.socket",
"activates": "dbus.service"
},
{
"listen": "/run/dmeventd-client",
"unit": "dm-event.socket",
"activates": "dm-event.service"
},
...
]
```
### systemctl list-unit-files
```
$ systemctl list-unit-files | jc --systemctl-luf -p
[
{
"unit_file": "proc-sys-fs-binfmt_misc.automount",
"state": "static"
},
{
"unit_file": "dev-hugepages.mount",
"state": "static"
},
{
"unit_file": "dev-mqueue.mount",
"state": "static"
},
...
]
```
2019-10-22 13:28:15 -07:00
### uname -a
```
$ uname -a | jc --uname -p
{
"kernel_name": "Linux",
"node_name": "user-ubuntu",
"kernel_release": "4.15.0-65-generic",
"operating_system": "GNU/Linux",
"hardware_platform": "x86_64",
"processor": "x86_64",
"machine": "x86_64",
"kernel_version": "#74 -Ubuntu SMP Tue Sep 17 17:06:04 UTC 2019"
}
```
2019-10-24 17:09:32 -07:00
### uptime
```
$ uptime | jc --uptime -p
{
2019-11-12 13:05:19 -08:00
"time": "11:30:44",
"uptime": "1 day, 21:17",
"users": 1,
"load_1m": 0.01,
"load_5m": 0.04,
"load_15m": 0.05
2019-10-24 17:09:32 -07:00
}
```
2019-10-24 16:06:55 -07:00
### w
```
$ w | jc --w -p
[
2019-11-12 13:05:19 -08:00
{
"user": "root",
"tty": "tty1",
"from": null,
"login_at": "07:49",
"idle": "1:15m",
"jcpu": "0.00s",
"pcpu": "0.00s",
"what": "-bash"
},
2019-10-24 16:06:55 -07:00
{
2019-10-25 14:58:15 -07:00
"user": "root",
"tty": "ttyS0",
2019-11-12 13:05:19 -08:00
"from": null,
"login_at": "06:24",
2019-10-25 14:58:15 -07:00
"idle": "0.00s",
2019-11-12 13:05:19 -08:00
"jcpu": "0.43s",
2019-10-25 14:58:15 -07:00
"pcpu": "0.00s",
2019-11-12 13:05:19 -08:00
"what": "w"
2019-10-24 16:06:55 -07:00
},
{
2019-10-25 14:58:15 -07:00
"user": "root",
"tty": "pts/0",
"from": "192.168.71.1",
2019-11-12 13:05:19 -08:00
"login_at": "06:29",
"idle": "2:35m",
"jcpu": "0.00s",
"pcpu": "0.00s",
2019-10-25 14:58:15 -07:00
"what": "-bash"
2019-10-24 16:06:55 -07:00
}
]
```
2019-11-12 13:35:32 -08:00
## TODO
Future parsers:
- nslookup
- journalctl
- /proc files
- /sys files
2019-10-18 13:34:28 -07:00
## Contributions
2019-11-12 14:10:26 -08:00
Feel free to add/improve code or parsers! You can use the `jc/parsers/foo.py` parser as a template and submit your parser with a pull request.
2019-10-18 13:34:28 -07:00
2019-10-29 10:27:42 -07:00
## Compatibility
2019-11-14 13:43:07 -08:00
Some parsers like `ls` , `ps` , `dig` , etc. will work on any platform. Other parsers that are platform-specific will generate a warning message if they are used on an unsupported platform. You may still use a parser on an unsupported platform - for example, you may want to parse a file with linux `lsof` output on an OSX laptop. In that case you can suppress the warning message with the `-q` cli option or the `quiet=True` function parameter in `parse()` :
2019-11-13 08:17:41 -08:00
```
$ cat lsof.out | jc --lsof -q
```
2019-10-29 10:27:42 -07:00
Tested on:
- Centos 7.7
- Ubuntu 18.4
2019-12-06 10:39:11 -08:00
- OSX 10.11.6
- OSX 10.14.6
2019-10-29 10:27:42 -07:00
2019-10-18 09:57:10 -07:00
## Acknowledgments
- `ifconfig-parser` module from https://github.com/KnightWhoSayNi/ifconfig-parser
2019-10-29 10:27:42 -07:00
- Parsing code from Conor Heine at https://gist.github.com/cahna/43a1a3ff4d075bcd71f9d7120037a501 adapted for some parsers