1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00
Files
jc/README.md

1382 lines
63 KiB
Markdown
Raw Permalink Normal View History

2022-03-08 13:19:20 -08:00
[![Pypi](https://img.shields.io/pypi/v/jc.svg)](https://pypi.org/project/jc/)
2020-04-02 10:55:32 -07:00
2022-01-23 13:40:50 -08:00
> Check out the `jc` Python [package documentation](https://github.com/kellyjonbrazil/jc/tree/master/docs) for developers
2023-01-27 08:15:53 -08:00
> Try the `jc` [web demo](https://jc-web.onrender.com/) and [REST API](https://github.com/kellyjonbrazil/jc-restapi)
2020-08-26 14:41:01 -07:00
2024-02-01 09:45:16 -08:00
> `jc` is available as an
[Ansible filter plugin](https://docs.ansible.com/ansible/latest/collections/community/general/jc_filter.html#ansible-collections-community-general-jc-filter)
in the `community.general` collection. See this
2022-01-23 13:40:50 -08:00
[blog post](https://blog.kellybrazil.com/2020/08/30/parsing-command-output-in-ansible-with-jc/)
for an example.
2020-08-20 10:35:49 -07:00
2019-10-15 15:06:09 -07:00
# JC
2022-03-04 13:27:39 -08:00
JSON Convert
2019-10-15 15:06:09 -07:00
2022-07-31 10:52:00 -07:00
`jc` JSONifies the output of many CLI tools, file-types, and common strings
for easier parsing in scripts. See the [**Parsers**](#parsers) section for
supported commands, file-types, and strings.
2020-06-25 21:11:21 -07:00
```bash
dig example.com | jc --dig
2020-06-25 21:11:21 -07:00
```
2020-06-25 12:28:23 -07:00
```json
2022-01-23 13:14:00 -08:00
[{"id":38052,"opcode":"QUERY","status":"NOERROR","flags":["qr","rd","ra"],
"query_num":1,"answer_num":1,"authority_num":0,"additional_num":1,
"opt_pseudosection":{"edns":{"version":0,"flags":[],"udp":4096}},"question":
{"name":"example.com.","class":"IN","type":"A"},"answer":[{"name":
"example.com.","class":"IN","type":"A","ttl":39049,"data":"93.184.216.34"}],
"query_time":49,"server":"2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)",
"when":"Fri Apr 16 16:09:00 PDT 2021","rcvd":56,"when_epoch":1618614540,
"when_epoch_utc":null}]
```
This allows further command-line processing of output with tools like `jq`
or [`jello`](https://github.com/kellyjonbrazil/jello) by piping commands:
2020-06-25 21:11:21 -07:00
```bash
$ dig example.com | jc --dig | jq -r '.[].answer[].data'
93.184.216.34
2020-06-25 21:12:30 -07:00
```
2022-01-23 13:14:00 -08:00
or using the alternative "magic" syntax:
2022-01-23 13:14:00 -08:00
```bash
$ jc dig example.com | jq -r '.[].answer[].data'
93.184.216.34
2020-02-13 17:20:00 -08:00
```
2022-01-23 13:14:00 -08:00
2023-01-27 14:47:08 -08:00
`jc` can also be used as a python library. In this case the returned value
will be a python dictionary, a list of dictionaries, or even a
2022-06-16 17:51:20 -07:00
[lazy iterable of dictionaries](#using-streaming-parsers-as-python-modules)
instead of JSON:
2020-06-25 12:28:23 -07:00
```python
2021-09-08 07:00:50 -07:00
>>> import subprocess
2022-01-18 13:40:09 -08:00
>>> import jc
>>>
2021-09-08 07:00:50 -07:00
>>> cmd_output = subprocess.check_output(['dig', 'example.com'], text=True)
2022-01-18 13:40:09 -08:00
>>> data = jc.parse('dig', cmd_output)
2019-11-12 11:46:52 -08:00
>>>
2022-03-04 16:29:36 -08:00
>>> data[0]['answer']
2022-01-23 13:14:00 -08:00
[{'name': 'example.com.', 'class': 'IN', 'type': 'A', 'ttl': 29658, 'data':
2022-03-04 16:29:36 -08:00
'93.184.216.34'}]
2019-10-25 15:39:48 -07:00
```
2022-01-19 21:53:13 -08:00
2022-01-23 13:14:00 -08:00
> For `jc` Python package documentation, use `help('jc')`, `help('jc.lib')`, or
2022-01-23 13:40:50 -08:00
see the [online documentation](https://github.com/kellyjonbrazil/jc/tree/master/docs).
2022-01-19 21:53:13 -08:00
2022-01-23 13:14:00 -08:00
Two representations of the data are available. 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-12 07:18:27 -08:00
2022-01-23 13:14:00 -08:00
To access the raw, pre-processed JSON, use the `-r` cli option or the `raw=True`
2022-09-09 17:13:43 -07:00
function parameter in `parse()` when using `jc` as a python library.
2019-11-12 07:18:27 -08:00
2022-01-23 13:14:00 -08:00
Schemas for each parser can be found at the documentation link beside each
[**Parser**](#parsers) below.
2019-10-21 14:13:31 -07:00
2024-02-20 08:56:53 -08:00
Release notes can be found in the [Releases section](https://github.com/kellyjonbrazil/jc/releases) on Github.
2020-03-03 11:37:59 -08:00
2020-06-26 09:53:57 -07:00
## Why Would Anyone Do This!?
2022-01-23 13:14:00 -08:00
For more information on the motivations for this project, please see my blog
2022-01-23 13:40:50 -08:00
post on [Bringing the Unix Philosophy to the 21st Century](https://blog.kellybrazil.com/2019/11/26/bringing-the-unix-philosophy-to-the-21st-century/) and my [interview with Console](https://console.substack.com/p/console-89).
2020-02-14 09:43:02 -08:00
2020-06-26 09:53:57 -07:00
See also:
- [libxo on FreeBSD](http://juniper.github.io/libxo/libxo-manual.html)
2022-01-23 13:40:50 -08:00
- [powershell](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/convertto-json?view=powershell-7)
- [blog: linux apps should have a json flag](https://thomashunter.name/posts/2012-06-06-linux-cli-apps-should-have-a-json-flag)
2021-09-17 10:20:22 -07:00
- [Hacker News discussion](https://news.ycombinator.com/item?id=28266193)
2022-01-23 13:40:50 -08:00
- [Reddit discussion](https://www.reddit.com/r/programming/comments/pa4cbb/bringing_the_unix_philosophy_to_the_21st_century/)
2020-06-26 09:53:57 -07:00
2021-05-05 09:20:47 -07:00
Use Cases:
2022-01-23 13:40:50 -08:00
- [Bash scripting](https://blog.kellybrazil.com/2021/04/12/practical-json-at-the-command-line/)
- [Ansible command output parsing](https://blog.kellybrazil.com/2020/08/30/parsing-command-output-in-ansible-with-jc/)
- [Saltstack command output parsing](https://blog.kellybrazil.com/2020/09/15/parsing-command-output-in-saltstack-with-jc/)
- [Nornir command output parsing](https://blog.kellybrazil.com/2020/12/09/parsing-command-output-in-nornir-with-jc/)
2022-07-31 17:19:04 -07:00
- [FortiSOAR command output parsing](https://docs.fortinet.com/document/fortisoar/1.0.0/jc-parse-command-output/323/jc-parse-command-output-v1-0-0)
2021-05-05 09:18:45 -07:00
2019-10-17 15:03:32 -07:00
## Installation
2022-01-23 13:14:00 -08:00
There are several ways to get `jc`. You can install via `pip`, OS package
[repositories](https://repology.org/project/jc/versions), or by downloading the
correct [binary](https://github.com/kellyjonbrazil/jc/releases) for your
architecture and running it anywhere on your filesystem.
2020-04-15 21:22:43 -07:00
2020-04-16 14:03:31 -07:00
### Pip (macOS, linux, unix, Windows)
2022-03-08 13:21:05 -08:00
[![Pypi](https://img.shields.io/pypi/v/jc.svg)](https://pypi.org/project/jc/)
2020-06-25 12:28:23 -07:00
```bash
pip3 install jc
2019-10-17 15:03:32 -07:00
```
2020-05-27 14:58:16 -07:00
### OS Package Repositories
2020-05-27 17:08:54 -07:00
2022-04-12 11:07:34 -07:00
| OS | Command |
|--------------------------------------|-------------------------------------------------------------------------------|
| Debian/Ubuntu linux | `apt-get install jc` |
| Fedora linux | `dnf install jc` |
| openSUSE linux | `zypper install jc` |
2022-11-03 11:29:06 +02:00
| Arch linux | `pacman -S jc` |
2022-04-12 11:07:34 -07:00
| NixOS linux | `nix-env -iA nixpkgs.jc` or `nix-env -iA nixos.jc` |
| Guix System linux | `guix install jc` |
2022-04-28 10:59:12 -07:00
| Gentoo Linux | `emerge dev-python/jc` |
2023-11-21 15:01:04 -08:00
| Photon linux | `tdnf install jc` |
2022-04-12 11:07:34 -07:00
| macOS | `brew install jc` |
| FreeBSD | `portsnap fetch update && cd /usr/ports/textproc/py-jc && make install clean` |
| Ansible filter plugin | `ansible-galaxy collection install community.general` |
2022-07-31 17:21:50 -07:00
| FortiSOAR connector | Install from FortiSOAR Connector Marketplace |
2020-05-27 14:58:16 -07:00
> For more OS Packages, see https://repology.org/project/jc/versions.
2022-02-01 17:57:12 -08:00
### Binaries
2022-01-23 13:40:50 -08:00
For precompiled binaries, see [Releases](https://github.com/kellyjonbrazil/jc/releases)
on Github.
2020-04-15 21:22:43 -07:00
2019-10-15 15:06:09 -07:00
## Usage
2022-01-23 13:14:00 -08:00
`jc` accepts piped input from `STDIN` and outputs a JSON representation of the
previous command's output to `STDOUT`.
2020-06-25 12:28:23 -07:00
```bash
2023-01-26 16:18:54 -08:00
COMMAND | jc [SLICE] [OPTIONS] PARSER
cat FILE | jc [SLICE] [OPTIONS] PARSER
echo STRING | jc [SLICE] [OPTIONS] PARSER
2020-02-13 17:20:00 -08:00
```
2022-01-23 13:14:00 -08:00
Alternatively, the "magic" syntax can be used by prepending `jc` to the command
2022-09-09 17:13:43 -07:00
to be converted or in front of the absolute path for Proc files. Options can be
passed to `jc` immediately before the command or Proc file path is given.
(Note: command aliases and shell builtins are not supported)
2020-06-25 12:28:23 -07:00
```bash
2023-01-26 16:18:54 -08:00
jc [SLICE] [OPTIONS] COMMAND
jc [SLICE] [OPTIONS] /proc/<path-to-procfile>
2019-10-21 13:47:22 -07:00
```
2022-01-23 13:14:00 -08:00
The JSON output can be compact (default) or pretty formatted with the `-p`
option.
2019-10-15 15:06:09 -07:00
2019-10-22 11:15:44 -07:00
### Parsers
2022-06-15 20:10:55 -07:00
| Argument | Command or Filetype | Documentation |
|-------------------|---------------------------------------------------------|----------------------------------------------------------------------------|
| `--acpi` | `acpi` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/acpi) |
| `--airport` | `airport -I` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/airport) |
| `--airport-s` | `airport -s` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/airport_s) |
2024-12-20 15:30:41 -08:00
| `--amixer` | `amixer` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/amixer) |
| `--apt-cache-show` | `apt-cache show` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/apt_cache_show) |
| `--apt-get-sqq` | `apt-get -sqq` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/apt_get_sqq) |
| `--arp` | `arp` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/arp) |
| `--asciitable` | ASCII and Unicode table parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/asciitable) |
| `--asciitable-m` | multi-line ASCII and Unicode table parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/asciitable_m) |
| `--blkid` | `blkid` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/blkid) |
2023-04-16 11:46:21 -07:00
| `--bluetoothctl` | `bluetoothctl` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/bluetoothctl) |
| `--cbt` | `cbt` (Google Bigtable) command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/cbt) |
| `--cef` | CEF string parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/cef) |
| `--cef-s` | CEF string streaming parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/cef_s) |
2023-04-29 16:34:23 -07:00
| `--certbot` | `certbot` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/certbot) |
| `--chage` | `chage --list` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/chage) |
| `--cksum` | `cksum` and `sum` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/cksum) |
| `--clf` | Common and Combined Log Format file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/clf) |
| `--clf-s` | Common and Combined Log Format file streaming parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/clf_s) |
| `--crontab` | `crontab` command and file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/crontab) |
| `--crontab-u` | `crontab` file parser with user support | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/crontab_u) |
| `--csv` | CSV file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/csv) |
| `--csv-s` | CSV file streaming parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/csv_s) |
2024-02-04 12:03:48 -08:00
| `--curl-head` | `curl --head` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/curl_head) |
| `--date` | `date` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/date) |
| `--datetime-iso` | ISO 8601 Datetime string parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/datetime_iso) |
2023-11-23 14:52:06 -08:00
| `--debconf-show` | `debconf-show` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/debconf_show) |
| `--df` | `df` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/df) |
| `--dig` | `dig` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/dig) |
| `--dir` | `dir` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/dir) |
| `--dmidecode` | `dmidecode` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/dmidecode) |
| `--dpkg-l` | `dpkg -l` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/dpkg_l) |
| `--du` | `du` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/du) |
2024-02-05 11:35:59 -08:00
| `--efibootmgr` | `efibootmgr` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/efibootmgr) |
2022-07-19 13:02:09 -07:00
| `--email-address` | Email Address string parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/email_address) |
| `--env` | `env` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/env) |
| `--ethtool` | `ethtool` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ethtool) |
| `--file` | `file` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/file) |
| `--find` | `find` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/find) |
| `--findmnt` | `findmnt` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/findmnt) |
| `--finger` | `finger` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/finger) |
| `--free` | `free` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/free) |
| `--fstab` | `/etc/fstab` file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/fstab) |
| `--git-log` | `git log` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/git_log) |
| `--git-log-s` | `git log` command streaming parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/git_log_s) |
2022-11-07 13:02:55 -08:00
| `--git-ls-remote` | `git ls-remote` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/git_ls_remote) |
| `--gpg` | `gpg --with-colons` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/gpg) |
| `--group` | `/etc/group` file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/group) |
| `--gshadow` | `/etc/gshadow` file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/gshadow) |
| `--hash` | `hash` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/hash) |
| `--hashsum` | hashsum command parser (`md5sum`, `shasum`, etc.) | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/hashsum) |
| `--hciconfig` | `hciconfig` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/hciconfig) |
| `--history` | `history` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/history) |
2023-09-30 15:32:27 -07:00
| `--host` | `host` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/host) |
| `--hosts` | `/etc/hosts` file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/hosts) |
2024-02-04 12:03:48 -08:00
| `--http-headers` | HTTP headers parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/http_headers) |
| `--id` | `id` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/id) |
| `--ifconfig` | `ifconfig` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ifconfig) |
| `--ini` | INI file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ini) |
| `--ini-dup` | INI with duplicate key file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ini_dup) |
| `--iostat` | `iostat` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/iostat) |
| `--iostat-s` | `iostat` command streaming parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/iostat_s) |
| `--ip-address` | IPv4 and IPv6 Address string parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ip_address) |
2024-10-18 14:34:29 -07:00
| `--ipconfig` | `ipconfig` Windows command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ipconfig) |
| `--iptables` | `iptables` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/iptables) |
| `--ip-route` | `ip route` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ip_route) |
| `--iw-scan` | `iw dev [device] scan` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/iw_scan) |
| `--iwconfig` | `iwconfig` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/iwconfig) |
| `--jar-manifest` | Java MANIFEST.MF file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/jar_manifest) |
| `--jobs` | `jobs` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/jobs) |
| `--jwt` | JWT string parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/jwt) |
| `--kv` | Key/Value file and string parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/kv) |
2023-12-22 09:45:43 -08:00
| `--kv-dup` | Key/Value with duplicate key file and string parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/kv_dup) |
| `--last` | `last` and `lastb` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/last) |
| `--ls` | `ls` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ls) |
| `--ls-s` | `ls` command streaming parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ls_s) |
Dev v1.23.3 (#426) * make certificate search more robust to different line endings * use license_files instead of license_file which is deprecated * version bump * parsing extra options -e, -o, -p * fix for extra opts and different field length at option -[aeop] * test integration for extra opts -e -o -p * formatting and use ast.literal_eval instead of eval * doc update * doc update * Add a parser to parse mounted encrypted veracrypt volumes (fixes #403) * update compatibility warning message * netstat windows parser * tests * Windows route parser * tests * id should be a string * add veracrypt parser and docs * formatting * doc update * lsattr parser * Update test_lsattr.py * changed keys to lowercase * changed info * support missing data for stat * doc update * doc update * doc update * ensure compatibility warning prints even with no data * improve compatibility message * add support for dig +nsid option * New parser: srt (#415) * srt parser * changed the parser to support more complex cases * doc updates * Adding certificate request parser (#416) * Adding certificate request parser * Adding the CSR type for Windows-style CSR --------- Co-authored-by: Stg22 <stephane.for.test@gmail.com> * doc update * add csr tests * Last -x (#422) * Refactored the parser * last -x support * doc update * fix for ping on linux with missing hostname * allow less strict email decoding with a warning. * doc update * use explicit ascii decode with backslashreplace * doc update * use jc warning function instead of print for warning message * last -x shutdown fix (#423) * inject quiet setting into asn1crypto library * Parse appearance and modalias lines for mouse devices (fixes #419) (#425) The bluetoothctl device parser is implemented so that it aborts the parsing process immediately returning what it has collected so far. This is because the parser should work in hydrid way to support outputs comming from bluetoothctl devices and bluetoothctl info calls. * doc update * doc update --------- Co-authored-by: gerd <gerd.augstein@gmail.com> Co-authored-by: Jake Ob <iakopap@gmail.com> Co-authored-by: Mevaser <mevaser.rotner@gmail.com> Co-authored-by: M.R <69431152+YeahItsMeAgain@users.noreply.github.com> Co-authored-by: Stg22 <46686290+Stg22@users.noreply.github.com> Co-authored-by: Stg22 <stephane.for.test@gmail.com>
2023-06-22 01:48:23 +03:00
| `--lsattr` | `lsattr` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/lsattr) |
2023-10-01 18:13:27 -07:00
| `--lsb-release` | `lsb_release` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/lsb_release) |
| `--lsblk` | `lsblk` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/lsblk) |
| `--lsmod` | `lsmod` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/lsmod) |
| `--lsof` | `lsof` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/lsof) |
| `--lspci` | `lspci -mmv` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/lspci) |
| `--lsusb` | `lsusb` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/lsusb) |
| `--m3u` | M3U and M3U8 file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/m3u) |
| `--mdadm` | `mdadm` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/mdadm) |
| `--mount` | `mount` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/mount) |
| `--mpstat` | `mpstat` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/mpstat) |
| `--mpstat-s` | `mpstat` command streaming parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/mpstat_s) |
2024-02-28 13:28:03 -08:00
| `--needrestart` | `needrestart -b` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/needrestart) |
| `--netstat` | `netstat` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/netstat) |
| `--nmcli` | `nmcli` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/nmcli) |
2023-09-30 15:45:29 -07:00
| `--nsd-control` | `nsd-control` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/nsd_control) |
| `--ntpq` | `ntpq -p` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ntpq) |
| `--openvpn` | openvpn-status.log file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/openvpn) |
| `--os-prober` | `os-prober` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/os_prober) |
2023-10-01 17:42:00 -07:00
| `--os-release` | `/etc/os-release` file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/os_release) |
2024-11-24 18:59:30 -08:00
| `--pacman` | `pacman` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/pacman) |
| `--passwd` | `/etc/passwd` file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/passwd) |
2024-01-30 20:19:32 -08:00
| `--path` | POSIX path string parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/path) |
| `--path-list` | POSIX path list string parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/path_list) |
| `--pci-ids` | `pci.ids` file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/pci_ids) |
| `--pgpass` | PostgreSQL password file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/pgpass) |
| `--pidstat` | `pidstat -H` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/pidstat) |
| `--pidstat-s` | `pidstat -H` command streaming parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/pidstat_s) |
| `--ping` | `ping` and `ping6` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ping) |
| `--ping-s` | `ping` and `ping6` command streaming parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ping_s) |
| `--pip-list` | `pip list` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/pip_list) |
| `--pip-show` | `pip show` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/pip_show) |
| `--pkg-index-apk` | Alpine Linux Package Index file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/pkg_index_apk) |
| `--pkg-index-deb` | Debian Package Index file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/pkg_index_deb) |
| `--plist` | PLIST file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/plist) |
| `--postconf` | `postconf -M` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/postconf) |
| `--proc` | `/proc/` file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/proc) |
| `--ps` | `ps` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ps) |
| `--resolve-conf` | `/etc/resolve.conf` file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/resolve_conf) |
| `--route` | `route` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/route) |
| `--rpm-qi` | `rpm -qi` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/rpm_qi) |
| `--rsync` | `rsync` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/rsync) |
| `--rsync-s` | `rsync` command streaming parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/rsync_s) |
| `--semver` | Semantic Version string parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/semver) |
| `--sfdisk` | `sfdisk` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/sfdisk) |
| `--shadow` | `/etc/shadow` file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/shadow) |
Dev v1.23.3 (#426) * make certificate search more robust to different line endings * use license_files instead of license_file which is deprecated * version bump * parsing extra options -e, -o, -p * fix for extra opts and different field length at option -[aeop] * test integration for extra opts -e -o -p * formatting and use ast.literal_eval instead of eval * doc update * doc update * Add a parser to parse mounted encrypted veracrypt volumes (fixes #403) * update compatibility warning message * netstat windows parser * tests * Windows route parser * tests * id should be a string * add veracrypt parser and docs * formatting * doc update * lsattr parser * Update test_lsattr.py * changed keys to lowercase * changed info * support missing data for stat * doc update * doc update * doc update * ensure compatibility warning prints even with no data * improve compatibility message * add support for dig +nsid option * New parser: srt (#415) * srt parser * changed the parser to support more complex cases * doc updates * Adding certificate request parser (#416) * Adding certificate request parser * Adding the CSR type for Windows-style CSR --------- Co-authored-by: Stg22 <stephane.for.test@gmail.com> * doc update * add csr tests * Last -x (#422) * Refactored the parser * last -x support * doc update * fix for ping on linux with missing hostname * allow less strict email decoding with a warning. * doc update * use explicit ascii decode with backslashreplace * doc update * use jc warning function instead of print for warning message * last -x shutdown fix (#423) * inject quiet setting into asn1crypto library * Parse appearance and modalias lines for mouse devices (fixes #419) (#425) The bluetoothctl device parser is implemented so that it aborts the parsing process immediately returning what it has collected so far. This is because the parser should work in hydrid way to support outputs comming from bluetoothctl devices and bluetoothctl info calls. * doc update * doc update --------- Co-authored-by: gerd <gerd.augstein@gmail.com> Co-authored-by: Jake Ob <iakopap@gmail.com> Co-authored-by: Mevaser <mevaser.rotner@gmail.com> Co-authored-by: M.R <69431152+YeahItsMeAgain@users.noreply.github.com> Co-authored-by: Stg22 <46686290+Stg22@users.noreply.github.com> Co-authored-by: Stg22 <stephane.for.test@gmail.com>
2023-06-22 01:48:23 +03:00
| `--srt` | SRT file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/srt) |
| `--ss` | `ss` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ss) |
| `--ssh-conf` | `ssh` config file and `ssh -G` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ssh_conf) |
| `--sshd-conf` | `sshd` config file and `sshd -T` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/sshd_conf) |
| `--stat` | `stat` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/stat) |
| `--stat-s` | `stat` command streaming parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/stat_s) |
2023-11-28 11:23:47 -08:00
| `--swapon` | `swapon` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/swapon) |
| `--sysctl` | `sysctl` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/sysctl) |
| `--syslog` | Syslog RFC 5424 string parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/syslog) |
| `--syslog-s` | Syslog RFC 5424 string streaming parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/syslog_s) |
| `--syslog-bsd` | Syslog RFC 3164 string parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/syslog_bsd) |
| `--syslog-bsd-s` | Syslog RFC 3164 string streaming parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/syslog_bsd_s) |
| `--systemctl` | `systemctl` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/systemctl) |
| `--systemctl-lj` | `systemctl list-jobs` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/systemctl_lj) |
| `--systemctl-ls` | `systemctl list-sockets` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/systemctl_ls) |
2022-06-15 20:10:55 -07:00
| `--systemctl-luf` | `systemctl list-unit-files` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/systemctl_luf) |
| `--systeminfo` | `systeminfo` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/systeminfo) |
| `--time` | `/usr/bin/time` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/time) |
| `--timedatectl` | `timedatectl status` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/timedatectl) |
| `--timestamp` | Unix Epoch Timestamp string parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/timestamp) |
| `--toml` | TOML file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/toml) |
| `--top` | `top -b` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/top) |
| `--top-s` | `top -b` command streaming parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/top_s) |
| `--tracepath` | `tracepath` and `tracepath6` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/tracepath) |
| `--traceroute` | `traceroute` and `traceroute6` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/traceroute) |
2023-11-23 11:49:04 -08:00
| `--tune2fs` | `tune2fs -l` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/tune2fs) |
| `--udevadm` | `udevadm info` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/udevadm) |
| `--ufw` | `ufw status` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ufw) |
| `--ufw-appinfo` | `ufw app info [application]` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ufw_appinfo) |
| `--uname` | `uname -a` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/uname) |
2022-06-15 20:10:55 -07:00
| `--update-alt-gs` | `update-alternatives --get-selections` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/update_alt_gs) |
| `--update-alt-q` | `update-alternatives --query` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/update_alt_q) |
| `--upower` | `upower` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/upower) |
| `--uptime` | `uptime` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/uptime) |
| `--url` | URL string parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/url) |
| `--ver` | Version string parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ver) |
Dev v1.23.3 (#426) * make certificate search more robust to different line endings * use license_files instead of license_file which is deprecated * version bump * parsing extra options -e, -o, -p * fix for extra opts and different field length at option -[aeop] * test integration for extra opts -e -o -p * formatting and use ast.literal_eval instead of eval * doc update * doc update * Add a parser to parse mounted encrypted veracrypt volumes (fixes #403) * update compatibility warning message * netstat windows parser * tests * Windows route parser * tests * id should be a string * add veracrypt parser and docs * formatting * doc update * lsattr parser * Update test_lsattr.py * changed keys to lowercase * changed info * support missing data for stat * doc update * doc update * doc update * ensure compatibility warning prints even with no data * improve compatibility message * add support for dig +nsid option * New parser: srt (#415) * srt parser * changed the parser to support more complex cases * doc updates * Adding certificate request parser (#416) * Adding certificate request parser * Adding the CSR type for Windows-style CSR --------- Co-authored-by: Stg22 <stephane.for.test@gmail.com> * doc update * add csr tests * Last -x (#422) * Refactored the parser * last -x support * doc update * fix for ping on linux with missing hostname * allow less strict email decoding with a warning. * doc update * use explicit ascii decode with backslashreplace * doc update * use jc warning function instead of print for warning message * last -x shutdown fix (#423) * inject quiet setting into asn1crypto library * Parse appearance and modalias lines for mouse devices (fixes #419) (#425) The bluetoothctl device parser is implemented so that it aborts the parsing process immediately returning what it has collected so far. This is because the parser should work in hydrid way to support outputs comming from bluetoothctl devices and bluetoothctl info calls. * doc update * doc update --------- Co-authored-by: gerd <gerd.augstein@gmail.com> Co-authored-by: Jake Ob <iakopap@gmail.com> Co-authored-by: Mevaser <mevaser.rotner@gmail.com> Co-authored-by: M.R <69431152+YeahItsMeAgain@users.noreply.github.com> Co-authored-by: Stg22 <46686290+Stg22@users.noreply.github.com> Co-authored-by: Stg22 <stephane.for.test@gmail.com>
2023-06-22 01:48:23 +03:00
| `--veracrypt` | `veracrypt` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/veracrypt) |
| `--vmstat` | `vmstat` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/vmstat) |
| `--vmstat-s` | `vmstat` command streaming parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/vmstat_s) |
| `--w` | `w` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/w) |
| `--wc` | `wc` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/wc) |
2024-11-24 18:59:30 -08:00
| `--wg-show` | `wg show` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/wg_show) |
| `--who` | `who` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/who) |
| `--x509-cert` | X.509 PEM and DER certificate file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/x509_cert) |
2025-05-27 09:06:26 -07:00
| `--x509-crl` | X.509 PEM and DER certificate revocation list file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/x509_crl) |
Dev v1.23.3 (#426) * make certificate search more robust to different line endings * use license_files instead of license_file which is deprecated * version bump * parsing extra options -e, -o, -p * fix for extra opts and different field length at option -[aeop] * test integration for extra opts -e -o -p * formatting and use ast.literal_eval instead of eval * doc update * doc update * Add a parser to parse mounted encrypted veracrypt volumes (fixes #403) * update compatibility warning message * netstat windows parser * tests * Windows route parser * tests * id should be a string * add veracrypt parser and docs * formatting * doc update * lsattr parser * Update test_lsattr.py * changed keys to lowercase * changed info * support missing data for stat * doc update * doc update * doc update * ensure compatibility warning prints even with no data * improve compatibility message * add support for dig +nsid option * New parser: srt (#415) * srt parser * changed the parser to support more complex cases * doc updates * Adding certificate request parser (#416) * Adding certificate request parser * Adding the CSR type for Windows-style CSR --------- Co-authored-by: Stg22 <stephane.for.test@gmail.com> * doc update * add csr tests * Last -x (#422) * Refactored the parser * last -x support * doc update * fix for ping on linux with missing hostname * allow less strict email decoding with a warning. * doc update * use explicit ascii decode with backslashreplace * doc update * use jc warning function instead of print for warning message * last -x shutdown fix (#423) * inject quiet setting into asn1crypto library * Parse appearance and modalias lines for mouse devices (fixes #419) (#425) The bluetoothctl device parser is implemented so that it aborts the parsing process immediately returning what it has collected so far. This is because the parser should work in hydrid way to support outputs comming from bluetoothctl devices and bluetoothctl info calls. * doc update * doc update --------- Co-authored-by: gerd <gerd.augstein@gmail.com> Co-authored-by: Jake Ob <iakopap@gmail.com> Co-authored-by: Mevaser <mevaser.rotner@gmail.com> Co-authored-by: M.R <69431152+YeahItsMeAgain@users.noreply.github.com> Co-authored-by: Stg22 <46686290+Stg22@users.noreply.github.com> Co-authored-by: Stg22 <stephane.for.test@gmail.com>
2023-06-22 01:48:23 +03:00
| `--x509-csr` | X.509 PEM and DER certificate request file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/x509_csr) |
| `--xml` | XML file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/xml) |
| `--xrandr` | `xrandr` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/xrandr) |
| `--yaml` | YAML file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/yaml) |
| `--zipinfo` | `zipinfo` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/zipinfo) |
2023-01-31 17:00:42 -08:00
| `--zpool-iostat` | `zpool iostat` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/zpool_iostat) |
2023-02-05 09:49:32 -08:00
| `--zpool-status` | `zpool status` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/zpool_status) |
2019-10-15 15:06:09 -07:00
2019-10-22 11:15:44 -07:00
### Options
2022-06-15 20:04:39 -07:00
2024-01-29 09:38:57 -08:00
| Short | Long | Description |
|-------|-----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `-a` | `--about` | About `jc`. Prints information about `jc` and the parsers (in JSON or YAML, of course!) |
| `-C` | `--force-color` | Force color output even when using pipes (overrides `-m` and the `NO_COLOR` env variable) |
| `-d` | `--debug` | Debug mode. Prints trace messages if parsing issues are encountered (use`-dd` for verbose debugging) |
| `-h` | `--help` | Help. Use `jc -h --parser_name` for parser documentation. Use twice to show hidden parsers (e.g. `-hh`). Use thrice to show parser categories (e.g. `-hhh`). |
| `-m` | `--monochrome` | Monochrome output |
| `-M` | `--meta-out` | Add metadata to output including timestamp, parser name, magic command, magic command exit code, etc. | |
| `-p` | `--pretty` | Pretty format the JSON output |
| `-q` | `--quiet` | Quiet mode. Suppresses parser warning messages (use `-qq` to ignore streaming parser errors) |
| `-r` | `--raw` | Raw output. Provides more literal output, typically with string values and no additional semantic processing |
| `-s` | `--slurp` | Slurp multiple lines into an array. (use `-hhh` to find compatible parsers) |
| `-u` | `--unbuffer` | Unbuffer output |
| `-v` | `--version` | Version information |
| `-y` | `--yaml-out` | YAML output |
| `-B` | `--bash-comp` | Generate Bash shell completion script ([more info](https://github.com/kellyjonbrazil/jc/wiki/Shell-Completions)) |
| `-Z` | `--zsh-comp` | Generate Zsh shell completion script ([more info](https://github.com/kellyjonbrazil/jc/wiki/Shell-Completions)) |
2023-01-27 15:22:36 -08:00
2023-01-26 16:18:54 -08:00
### Slice
Line slicing is supported using the `START:STOP` syntax similar to Python
slicing. This allows you to skip lines at the beginning and/or end of the
2023-01-27 08:01:32 -08:00
`STDIN` input you would like `jc` to convert.
2023-01-26 16:18:54 -08:00
2023-01-26 16:59:15 -08:00
`START` and `STOP` can be positive or negative integers or blank and allow
you to specify how many lines to skip and how many lines to process.
Positive and blank slices are the most memory efficient. Any negative
integers in the slice will use more memory.
2023-01-26 16:18:54 -08:00
For example, to skip the first and last line of the following text, you
could express the slice in a couple ways:
```bash
$ cat table.txt
2023-01-26 16:46:54 -08:00
### We want to skip this header ###
col1 col2
foo 1
2023-01-26 16:49:27 -08:00
bar 2
2023-01-26 16:46:54 -08:00
### We want to skip this footer ###
2023-01-26 16:18:54 -08:00
$ cat table.txt | jc 1:-1 --asciitable
2023-01-26 16:49:27 -08:00
[{"col1":"foo","col2":"1"},{"col1":"bar","col2":"2"}]
2023-01-26 16:18:54 -08:00
$ cat table.txt | jc 1:4 --asciitable
2023-01-26 16:49:27 -08:00
[{"col1":"foo","col2":"1"},{"col1":"bar","col2":"2"}]
2023-01-26 16:18:54 -08:00
```
2023-01-26 16:24:32 -08:00
In this example `1:-1` and `1:4` line slices provide the same output.
2023-01-27 08:01:32 -08:00
When using positive integers the index location of `STOP` is non-inclusive.
Positive slices count from the first line of the input toward the end
starting at `0` as the first line. Negative slices count from the last line
toward the beginning starting at `-1` as the last line. This is also the way
[Python's slicing](https://stackoverflow.com/questions/509211/understanding-slicing)
2023-01-26 16:18:54 -08:00
feature works.
2023-01-27 11:31:16 -08:00
Here is a breakdown of line slice options:
2023-01-26 16:18:54 -08:00
2023-01-27 08:02:07 -08:00
| Slice Notation | Input Lines Processed |
2023-01-26 17:06:07 -08:00
|----------------|--------------------------------------------------------------|
| `START:STOP` | lines `START` through `STOP - 1` |
| `START:` | lines `START` through the rest of the output |
| `:STOP` | lines from the beginning through `STOP - 1` |
| `-START:STOP` | `START` lines from the end through `STOP - 1` |
| `START:-STOP` | lines `START` through `STOP` lines from the end |
| `-START:-STOP` | `START` lines from the end through `STOP` lines from the end |
| `-START:` | `START` lines from the end through the rest of the output |
| `:-STOP` | lines from the beginning through `STOP` lines from the end |
| `:` | all lines |
2023-01-26 16:18:54 -08:00
2024-01-26 12:25:26 -08:00
### Slurp
Some parsers support multi-item input and can output an array of results in a
single pass. Slurping works for string parsers that accept a single line of
input. (e.g. `url` and `ip-address`) To see a list of parsers that support
the `--slurp` option, use `jc -hhh`.
For example, you can send a file with multiple IP addresses (one per line) to
`jc` with the `--slurp` option and an array of results will output:
```bash
$ cat ip-addresses.txt | jc --slurp --ip-address
[<multiple output objects>]
```
The magic syntax for `/proc` files automatically supports slurping of multiple
files (no need to use the `--slurp` option). For example, you can convert many
PID files at once:
```bash
$ jc /proc/*/status
[<multiple output objects>]
```
When the `/proc` magic syntax is used and multiple files are selected, an
additional `_file` field is inserted in the output so it is easier to tell what
file each output object refers to.
Finally, the `--meta-out` option can be used in conjunction with slurped output.
In this case, the slurped output is wrapped in an object with the following
structure:
```json
{
"result": [<multiple output objects>],
"_jc_meta": {
"parser": "url",
"timestamp": 1706235558.654576,
"slice_start": null,
"slice_end": null,
"input_list": [
"http://www.google.com",
"https://www.apple.com",
"https://www.microsoft.com"
]
}
}
```
With `--meta-out`, `input_list` contains a list of inputs (actual input strings
or `/proc` filenames) so you can identify which output object relates to each
input string or `/proc` filename.
2021-05-11 10:59:26 -07:00
### Exit Codes
2022-01-23 13:14:00 -08:00
Any fatal errors within `jc` will generate an exit code of `100`, otherwise the
exit code will be `0`.
When using the "magic" syntax (e.g. `jc ifconfig eth0`),
2022-01-23 13:14:00 -08:00
`jc` will store the exit code of the program being parsed and add it to the `jc`
exit code. This way it is easier to determine if an error was from the parsed
program or `jc`.
2021-05-11 10:59:26 -07:00
Consider the following examples using `ifconfig`:
2021-05-17 08:38:09 -07:00
2022-01-23 13:14:00 -08:00
| `ifconfig` exit code | `jc` exit code | Combined exit code | Interpretation |
2021-05-11 11:32:08 -07:00
|----------------------|----------------|--------------------|------------------------------------|
| `0` | `0` | `0` | No errors |
| `1` | `0` | `1` | Error in `ifconfig` |
| `0` | `100` | `100` | Error in `jc` |
| `1` | `100` | `101` | Error in both `ifconfig` and `jc` |
When using the "magic" syntax you can also retrieve the exit code of the called
program by using the `--meta-out` or `-M` option. This will append a `_jc_meta`
object to the output that will include the magic command information, including
the exit code.
Here is an example with `ping`:
2022-08-24 09:11:06 -07:00
```bash
$ jc --meta-out -p ping -c2 192.168.1.252
{
"destination_ip": "192.168.1.252",
"data_bytes": 56,
"pattern": null,
"destination": "192.168.1.252",
"packets_transmitted": 2,
"packets_received": 0,
"packet_loss_percent": 100.0,
"duplicates": 0,
"responses": [
{
"type": "timeout",
"icmp_seq": 0,
"duplicate": false
}
],
"_jc_meta": {
"parser": "ping",
"timestamp": 1661357115.27949,
"magic_command": [
"ping",
"-c2",
"192.168.1.252"
],
"magic_command_exit": 2
}
}
2022-08-24 09:11:06 -07:00
$ echo $?
2
```
2021-05-11 10:59:26 -07:00
2020-04-12 13:10:57 -07:00
### Setting Custom Colors via Environment Variable
2022-01-23 13:14:00 -08:00
You can specify custom colors via the `JC_COLORS` environment variable. The
`JC_COLORS` environment variable takes four comma separated string values in
the following format:
2020-06-25 12:28:23 -07:00
```bash
2020-04-12 13:23:58 -07:00
JC_COLORS=<keyname_color>,<keyword_color>,<number_color>,<string_color>
2020-04-12 13:10:57 -07:00
```
2022-01-23 13:14:00 -08:00
Where colors are: `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`,
`gray`, `brightblack`, `brightred`, `brightgreen`, `brightyellow`, `brightblue`,
`brightmagenta`, `brightcyan`, `white`, or `default`
2020-04-12 13:10:57 -07:00
For example, to set to the default colors:
2020-06-25 12:28:23 -07:00
```bash
2020-04-12 13:10:57 -07:00
JC_COLORS=blue,brightblack,magenta,green
```
or
2020-06-25 12:28:23 -07:00
```bash
2020-04-12 13:10:57 -07:00
JC_COLORS=default,default,default,default
```
2021-12-08 08:35:09 -08:00
### Disable Colors via Environment Variable
2022-01-23 13:14:00 -08:00
You can set the [`NO_COLOR`](http://no-color.org/) environment variable to any
value to disable color output in `jc`. Note that using the `-C` option to force
color output will override both the `NO_COLOR` environment variable and the `-m`
option.
2021-12-08 08:35:09 -08:00
2021-09-16 21:31:45 -07:00
### Streaming Parsers
2022-05-26 16:03:30 -07:00
Most parsers load all of the data from `STDIN`, parse it, then output the entire
2022-01-23 13:14:00 -08:00
JSON document serially. There are some streaming parsers (e.g. `ls-s` and
`ping-s`) that immediately start processing and outputting the data line-by-line
2022-01-23 13:14:00 -08:00
as [JSON Lines](https://jsonlines.org/) (aka [NDJSON](http://ndjson.org/)) while
2022-05-26 16:03:30 -07:00
it is being received from `STDIN`. This can significantly reduce the amount of
2022-01-23 13:14:00 -08:00
memory required to parse large amounts of command output (e.g. `ls -lR /`) and
can sometimes process the data more quickly. Streaming parsers have slightly
different behavior than standard parsers as outlined below.
2021-09-16 21:31:45 -07:00
> Note: Streaming parsers cannot be used with the "magic" syntax
2021-09-23 08:54:15 -07:00
#### Ignoring Errors
2021-09-16 21:33:57 -07:00
2022-01-23 13:14:00 -08:00
You may want to ignore parsing errors when using streaming parsers since these
may be used in long-lived processing pipelines and errors can break the pipe. To
ignore parsing errors, use the `-qq` cli option or the `ignore_exceptions=True`
argument with the `parse()` function. This will add a `_jc_meta` object to the
JSON output with a `success` attribute. If `success` is `true`, then there were
no issues parsing the line. If `success` is `false`, then a parsing issue was
found and `error` and `line` fields will be added to include a short error
description and the contents of the unparsable line, respectively:
2021-09-16 21:31:45 -07:00
2021-09-23 11:54:58 -07:00
Successfully parsed line with `-qq` option:
2021-09-23 08:59:26 -07:00
```json
2021-09-16 21:31:45 -07:00
{
"command_data": "data",
2021-09-23 13:08:31 -07:00
"_jc_meta": {
2021-09-16 21:31:45 -07:00
"success": true
}
}
```
2022-01-23 13:14:00 -08:00
2021-09-23 11:54:58 -07:00
Unsuccessfully parsed line with `-qq` option:
2021-09-23 08:59:26 -07:00
```json
2021-09-16 21:31:45 -07:00
{
2021-09-23 13:08:31 -07:00
"_jc_meta": {
2021-09-16 21:31:45 -07:00
"success": false,
2021-09-23 12:58:24 -07:00
"error": "error message",
2021-09-16 21:31:45 -07:00
"line": "original line data"
}
}
```
2021-09-23 08:54:15 -07:00
#### Unbuffering Output
2021-09-16 21:33:57 -07:00
2022-01-23 13:14:00 -08:00
Most operating systems will buffer output that is being piped from process to
process. The buffer is usually around 4KB. When viewing the output in the
terminal the OS buffer is not engaged so output is immediately displayed on the
screen. When piping multiple processes together, though, it may seem as if the
output is hanging when the input data is very slow (e.g. `ping`):
2021-09-16 21:31:45 -07:00
```
$ ping 1.1.1.1 | jc --ping-s | jq
<slow output>
```
2022-01-23 13:14:00 -08:00
This is because the OS engages the 4KB buffer between `jc` and `jq` in this
example. To display the data on the terminal in realtime, you can disable the
buffer with the `-u` (unbuffer) cli option:
2021-09-16 21:31:45 -07:00
```
$ ping 1.1.1.1 | jc --ping-s -u | jq
2022-01-23 13:14:00 -08:00
{"type":"reply","pattern":null,"timestamp":null,"bytes":"64","respons...}
{"type":"reply","pattern":null,"timestamp":null,"bytes":"64","respons...}
2021-09-16 21:31:45 -07:00
...
```
2022-01-23 13:14:00 -08:00
> Note: Unbuffered output can be slower for large data streams.
2021-09-23 08:54:15 -07:00
#### Using Streaming Parsers as Python Modules
2022-04-29 06:42:11 -07:00
Streaming parsers accept any iterable object and return an iterable object
allowing lazy processing of the data. The input data should iterate on lines
of string data. Examples of good input data are `sys.stdin` or
2022-01-23 13:14:00 -08:00
`str.splitlines()`.
2022-04-29 06:47:10 -07:00
To use the returned iterable object in your code, simply loop through it or
use the [next()](https://docs.python.org/3/library/functions.html#next)
builtin function:
2021-09-23 08:57:14 -07:00
```python
2022-01-18 13:40:09 -08:00
import jc
2022-01-18 13:40:09 -08:00
result = jc.parse('ls_s', ls_command_output.splitlines())
for item in result:
2021-09-23 08:56:14 -07:00
print(item["filename"])
```
2021-09-16 21:31:45 -07:00
### Parser Plugins
Parser plugins may be placed in a `jc/jcparsers` folder in your local
**"App data directory"**:
- Linux/unix: `$HOME/.local/share/jc/jcparsers`
- macOS: `$HOME/Library/Application Support/jc/jcparsers`
2020-06-08 10:48:58 -07:00
- Windows: `$LOCALAPPDATA\jc\jc\jcparsers`
Parser plugins are standard python module files. Use the
2022-01-23 13:40:50 -08:00
[`jc/parsers/foo.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/foo.py)
or [`jc/parsers/foo_s.py (streaming)`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/foo_s.py)
parser as a template and simply place a `.py` file in the `jcparsers` subfolder.
Any dependencies can be placed in the `jc` folder above `jcparsers` and can
be imported in the parser code.
Parser plugin filenames must be valid python module names and therefore must
2022-04-29 06:47:10 -07:00
start with a letter and consist entirely of alphanumerics and underscores.
Local plugins may override default parsers.
2022-01-23 13:40:50 -08:00
> Note: The application data directory follows the
[XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html)
2021-04-25 21:06:47 -07:00
### Caveats
2021-09-23 21:13:21 -07:00
2021-09-23 21:14:47 -07:00
#### Locale
2021-04-25 21:10:21 -07:00
2022-07-27 17:21:04 -07:00
For best results set the locale environment variables to `C` or
`en_US.UTF-8` by modifying the `LC_ALL` variable:
2021-04-25 21:06:47 -07:00
```
2022-07-27 17:21:04 -07:00
$ LC_ALL=C date | jc --date
2021-04-25 21:06:47 -07:00
```
2022-01-23 13:14:00 -08:00
2022-07-27 17:21:04 -07:00
You can also set the locale variables individually:
2021-04-25 21:06:47 -07:00
```
$ export LANG=C
2022-07-27 17:21:04 -07:00
$ export LC_NUMERIC=C
2021-04-25 21:06:47 -07:00
```
2022-04-26 17:51:30 -07:00
On some older systems UTF-8 output will be downgraded to ASCII with `\\u`
escape sequences if the `C` locale does not support UTF-8 encoding.
2021-09-23 21:14:47 -07:00
#### Timezones
2021-04-25 21:10:21 -07:00
2022-01-23 13:14:00 -08:00
Some parsers have calculated epoch timestamp fields added to the output. Unless
a timestamp field name has a `_utc` suffix it is considered naive. (i.e. based
on the local timezone of the system the `jc` parser was run on).
2021-04-25 21:06:47 -07:00
2022-01-23 13:14:00 -08:00
If a UTC timezone can be detected in the text of the command output, the
timestamp will be timezone aware and have a `_utc` suffix on the key name.
(e.g. `epoch_utc`) No other timezones are supported for aware timestamps.
2021-04-25 21:06:47 -07:00
## Use In Other Shells
`jc` can be used in most any shell. Some modern shells have JSON deserialization
and filtering capabilities built-in which makes using `jc` even more convenient.
For example, the following is possible in [NGS](https://ngs-lang.org/)
(Next Generation Shell):
```bash
myvar = ``jc dig www.google.com``[0].answer[0].data
```
2022-05-20 07:58:19 -07:00
This runs `jc`, parses the output JSON, and assigs the resulting data structure
to a variable in a single line of code.
For more examples of how to use `jc` in other shells, see this
2022-05-20 07:58:19 -07:00
[wiki page](https://github.com/kellyjonbrazil/jc/wiki/Using-jc-With-Different-Shells).
2020-02-27 09:36:57 -08:00
## Compatibility
2022-01-23 13:14:00 -08:00
Some parsers like `dig`, `xml`, `csv`, etc. will work on any platform. Other
parsers that convert platform-specific output will generate a warning message if
they are run on an unsupported platform. To see all parser information,
including compatibility, run `jc -ap`.
2020-02-27 09:36:57 -08:00
2022-05-20 07:58:19 -07:00
You may still use a parser on an unsupported platform - for example, you may
2023-03-18 11:07:15 +01:00
want to parse a file with linux `lsof` output on a macOS or Windows laptop. In
2022-05-20 07:58:19 -07:00
that case you can suppress the warning message with the `-q` cli option or the
2022-01-23 13:14:00 -08:00
`quiet=True` function parameter in `parse()`:
2020-02-27 09:36:57 -08:00
2021-05-21 10:16:08 -07:00
macOS:
2020-06-25 12:28:23 -07:00
```bash
2022-09-07 13:56:16 -07:00
cat lsof.out | jc -q --lsof
2020-02-27 09:36:57 -08:00
```
2022-01-23 13:14:00 -08:00
2021-05-21 10:16:08 -07:00
or Windows:
```bash
2022-09-07 13:56:16 -07:00
type lsof.out | jc -q --lsof
2021-05-21 10:16:08 -07:00
```
2020-02-27 09:36:57 -08:00
Tested on:
- Centos 7.7
- Ubuntu 18.04
- Ubuntu 20.04
2020-05-21 09:07:01 -07:00
- Fedora32
2021-04-04 15:57:44 -07:00
- macOS 10.11.6
- macOS 10.14.6
- NixOS
- FreeBSD12
2021-04-02 12:14:26 -07:00
- Windows 10
2021-05-21 10:16:08 -07:00
- Windows 2016 Server
- Windows 2019 Server
2020-02-27 09:36:57 -08:00
2020-05-21 09:07:01 -07:00
## Contributions
2022-01-23 13:40:50 -08:00
Feel free to add/improve code or parsers! You can use the
[`jc/parsers/foo.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/foo.py)
2022-05-20 07:58:19 -07:00
or [`jc/parsers/foo_s.py (streaming)`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/foo_s.py) parsers as a template and submit your parser with a pull
request.
2020-05-21 09:07:01 -07:00
2022-01-23 13:40:50 -08:00
Please see the [Contributing Guidelines](https://github.com/kellyjonbrazil/jc/blob/master/CONTRIBUTING.md) for more information.
2021-04-02 13:19:47 -07:00
2020-02-27 09:36:57 -08:00
## Acknowledgments
2022-01-23 13:40:50 -08:00
- Local parser plugin feature contributed by [Dean Serenevy](https://github.com/duelafn)
- CI automation and code optimizations by [philippeitis](https://github.com/philippeitis)
2022-01-23 13:14:00 -08:00
- [`ifconfig-parser`](https://github.com/KnightWhoSayNi/ifconfig-parser) module
by KnightWhoSayNi
2020-06-07 12:29:10 -07:00
- [`xmltodict`](https://github.com/martinblech/xmltodict) module by Martín Blech
2022-01-23 13:14:00 -08:00
- [`ruamel.yaml`](https://pypi.org/project/ruamel.yaml) module by Anthon van
der Neut
2020-07-27 10:33:15 -07:00
- [`trparse`](https://github.com/lbenitez000/trparse) module by Luis Benitez
2022-01-23 13:14:00 -08:00
- Parsing [code](https://gist.github.com/cahna/43a1a3ff4d075bcd71f9d7120037a501)
from Conor Heine adapted for some parsers
2020-06-07 12:29:10 -07:00
- Excellent constructive feedback from [Ilya Sher](https://github.com/ilyash-b)
2020-02-27 09:36:57 -08:00
2019-10-15 15:06:09 -07:00
## Examples
2022-01-23 13:14:00 -08:00
Here are some examples of `jc` output. For more examples, see
[here](https://kellyjonbrazil.github.io/jc/EXAMPLES) or the parser
documentation.
2019-10-30 13:22:12 -07:00
### arp
2020-06-25 21:11:21 -07:00
```bash
2022-09-07 13:56:16 -07:00
arp | jc -p --arp # or: jc -p arp
2020-06-25 21:11:21 -07:00
```
2020-06-25 12:56:06 -07:00
```json
2019-10-30 13:22:12 -07:00
[
{
"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"
}
]
```
2020-03-02 14:07:29 -08:00
### CSV files
2020-06-25 21:11:21 -07:00
```bash
cat homes.csv
```
2020-06-25 13:01:10 -07:00
```
2020-03-02 14:07:29 -08:00
"Sell", "List", "Living", "Rooms", "Beds", "Baths", "Age", "Acres", "Taxes"
142, 160, 28, 10, 5, 3, 60, 0.28, 3167
175, 180, 18, 8, 4, 1, 12, 0.43, 4033
129, 132, 13, 6, 3, 1, 41, 0.33, 1471
...
2020-06-25 13:01:10 -07:00
```
2020-06-25 21:11:21 -07:00
```bash
2022-09-07 13:56:16 -07:00
cat homes.csv | jc -p --csv
2020-06-25 21:11:21 -07:00
```
2020-06-25 13:01:10 -07:00
```json
2020-03-02 14:07:29 -08:00
[
{
"Sell": "142",
"List": "160",
"Living": "28",
"Rooms": "10",
"Beds": "5",
"Baths": "3",
"Age": "60",
"Acres": "0.28",
"Taxes": "3167"
},
{
"Sell": "175",
"List": "180",
"Living": "18",
"Rooms": "8",
"Beds": "4",
"Baths": "1",
"Age": "12",
"Acres": "0.43",
"Taxes": "4033"
},
{
"Sell": "129",
"List": "132",
"Living": "13",
"Rooms": "6",
"Beds": "3",
"Baths": "1",
"Age": "41",
"Acres": "0.33",
"Taxes": "1471"
2020-06-25 12:56:06 -07:00
}
2020-03-02 14:07:29 -08:00
]
```
2020-02-04 21:46:52 -08:00
### /etc/hosts file
2020-06-25 21:11:21 -07:00
```bash
2022-09-07 13:56:16 -07:00
cat /etc/hosts | jc -p --hosts
2020-06-25 21:11:21 -07:00
```
2020-06-25 12:56:06 -07:00
```json
2019-11-14 21:59:06 -08:00
[
{
"ip": "127.0.0.1",
"hostname": [
"localhost"
]
},
{
"ip": "::1",
"hostname": [
"ip6-localhost",
"ip6-loopback"
]
},
{
"ip": "fe00::0",
"hostname": [
"ip6-localnet"
]
}
]
```
2020-07-29 11:40:47 -07:00
### ifconfig
2020-06-25 21:11:21 -07:00
```bash
2022-09-07 13:56:16 -07:00
ifconfig | jc -p --ifconfig # or: jc -p ifconfig
2020-06-25 21:11:21 -07:00
```
2020-06-25 12:56:06 -07:00
```json
2019-10-15 15:32:23 -07:00
[
{
"name": "ens33",
2019-11-12 13:05:19 -08:00
"flags": 4163,
"state": [
"UP",
"BROADCAST",
"RUNNING",
"MULTICAST"
],
2019-11-12 13:05:19 -08:00
"mtu": 1500,
"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,
"ipv6_scope": "0x20",
2019-10-15 15:32:23 -07:00
"mac_addr": "00:0c:29:3b:58:0e",
"type": "Ethernet",
"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,
"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
}
]
2019-10-17 15:03:32 -07:00
```
2020-07-29 11:49:00 -07:00
### INI files
2020-06-25 21:11:21 -07:00
```bash
cat example.ini
```
2020-02-03 21:38:08 -08:00
```
2023-01-08 19:46:13 -08:00
foo = fiz
bar = buz
2020-02-03 21:38:08 -08:00
2023-01-08 19:46:13 -08:00
[section1]
fruit = apple
color = blue
2020-02-03 21:38:08 -08:00
2023-01-08 19:46:13 -08:00
[section2]
fruit = pear
color = green
2020-06-25 12:56:06 -07:00
```
2020-06-25 21:11:21 -07:00
```bash
2022-09-07 13:56:16 -07:00
cat example.ini | jc -p --ini
2020-06-25 21:11:21 -07:00
```
2020-06-25 12:56:06 -07:00
```json
2020-02-03 21:38:08 -08:00
{
2023-01-08 19:46:13 -08:00
"foo": "fiz",
"bar": "buz",
"section1": {
"fruit": "apple",
"color": "blue"
2023-01-08 10:55:48 -08:00
},
2023-01-08 19:46:13 -08:00
"section2": {
"fruit": "pear",
"color": "green"
2020-02-03 21:38:08 -08:00
}
}
```
2019-10-21 17:26:00 -07:00
### ls
2020-06-25 21:11:21 -07:00
```bash
2022-09-07 13:56:16 -07:00
$ ls -l /usr/bin | jc -p --ls # or: jc -p ls -l /usr/bin
2020-06-25 21:11:21 -07:00
```
```json
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"
2020-06-25 12:56:06 -07:00
}
2019-10-21 17:26:00 -07:00
]
```
2019-10-18 09:57:10 -07:00
### netstat
2020-06-25 21:11:21 -07:00
```bash
2022-09-07 13:56:16 -07:00
netstat -apee | jc -p --netstat # or: jc -p netstat -apee
2020-06-25 21:11:21 -07:00
```
2020-06-25 12:56:06 -07:00
```json
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": "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
2020-06-25 12:56:06 -07:00
}
2019-10-21 13:47:22 -07:00
]
2020-06-25 21:11:21 -07:00
```
### /etc/passwd file
2020-06-25 21:11:21 -07:00
```bash
2022-09-07 13:56:16 -07:00
cat /etc/passwd | jc -p --passwd
2020-06-25 21:11:21 -07:00
```
2020-06-25 12:56:06 -07:00
```json
[
{
"username": "root",
"password": "*",
"uid": 0,
"gid": 0,
"comment": "System Administrator",
"home": "/var/root",
"shell": "/bin/sh"
},
{
"username": "daemon",
"password": "*",
"uid": 1,
"gid": 1,
"comment": "System Services",
"home": "/var/root",
"shell": "/usr/bin/false"
2020-06-25 12:56:06 -07:00
}
]
```
2020-07-27 09:29:30 -07:00
### ping
```bash
2022-09-07 13:56:16 -07:00
ping 8.8.8.8 -c 3 | jc -p --ping # or: jc -p ping 8.8.8.8 -c 3
2020-07-27 09:29:30 -07:00
```
```json
{
"destination_ip": "8.8.8.8",
"data_bytes": 56,
"pattern": null,
"destination": "8.8.8.8",
"packets_transmitted": 3,
"packets_received": 3,
"packet_loss_percent": 0.0,
"duplicates": 0,
"time_ms": 2005.0,
"round_trip_ms_min": 23.835,
"round_trip_ms_avg": 30.46,
"round_trip_ms_max": 34.838,
"round_trip_ms_stddev": 4.766,
"responses": [
{
"type": "reply",
"timestamp": null,
"bytes": 64,
"response_ip": "8.8.8.8",
"icmp_seq": 1,
"ttl": 118,
"time_ms": 23.8,
"duplicate": false
},
{
"type": "reply",
"timestamp": null,
"bytes": 64,
"response_ip": "8.8.8.8",
"icmp_seq": 2,
"ttl": 118,
"time_ms": 34.8,
"duplicate": false
},
{
"type": "reply",
"timestamp": null,
"bytes": 64,
"response_ip": "8.8.8.8",
"icmp_seq": 3,
"ttl": 118,
"time_ms": 32.7,
"duplicate": false
}
]
}
```
2019-10-18 13:34:28 -07:00
### ps
2020-06-25 21:11:21 -07:00
```bash
2022-09-07 13:56:16 -07:00
ps axu | jc -p --ps # or: jc -p ps axu
2020-06-25 21:11:21 -07:00
```
2020-06-25 12:56:06 -07:00
```json
2019-11-12 13:05:19 -08:00
[
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",
2022-01-23 13:14:00 -08:00
"command": "/usr/lib/systemd/systemd --switched-root --system --deseria..."
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]"
2020-06-25 12:56:06 -07:00
}
2019-10-18 13:34:28 -07:00
]
```
2020-07-27 09:29:30 -07:00
### traceroute
```bash
2022-09-07 13:56:16 -07:00
traceroute -m 2 8.8.8.8 | jc -p --traceroute
2022-01-23 13:14:00 -08:00
# or: jc -p traceroute -m 2 8.8.8.8
2020-07-27 09:29:30 -07:00
```
```json
{
"destination_ip": "8.8.8.8",
"destination_name": "8.8.8.8",
"hops": [
{
"hop": 1,
"probes": [
{
"annotation": null,
"asn": null,
"ip": "192.168.1.254",
"name": "dsldevice.local.net",
"rtt": 6.616
},
{
"annotation": null,
"asn": null,
"ip": "192.168.1.254",
"name": "dsldevice.local.net",
"rtt": 6.413
},
{
"annotation": null,
"asn": null,
"ip": "192.168.1.254",
"name": "dsldevice.local.net",
"rtt": 6.308
}
]
},
{
"hop": 2,
"probes": [
{
"annotation": null,
"asn": null,
"ip": "76.220.24.1",
"name": "76-220-24-1.lightspeed.sntcca.sbcglobal.net",
"rtt": 29.367
},
{
"annotation": null,
"asn": null,
"ip": "76.220.24.1",
"name": "76-220-24-1.lightspeed.sntcca.sbcglobal.net",
"rtt": 40.197
},
{
"annotation": null,
"asn": null,
"ip": "76.220.24.1",
"name": "76-220-24-1.lightspeed.sntcca.sbcglobal.net",
"rtt": 29.162
}
]
}
]
}
```
2019-10-24 17:09:32 -07:00
### uptime
2020-06-25 21:11:21 -07:00
```bash
2022-09-07 13:56:16 -07:00
uptime | jc -p --uptime # or: jc -p uptime
2020-06-25 21:11:21 -07:00
```
2020-06-25 12:56:06 -07:00
```json
2019-10-24 17:09:32 -07:00
{
2021-03-25 11:43:30 -07:00
"time": "11:35",
"uptime": "3 days, 4:03",
"users": 5,
"load_1m": 1.88,
"load_5m": 2.0,
"load_15m": 1.94,
"time_hour": 11,
"time_minute": 35,
"time_second": null,
"uptime_days": 3,
"uptime_hours": 4,
"uptime_minutes": 3,
"uptime_total_seconds": 273780
2019-10-24 17:09:32 -07:00
}
```
2020-02-04 21:46:52 -08:00
### XML files
2020-06-25 21:11:21 -07:00
```bash
cat cd_catalog.xml
2020-02-03 22:13:06 -08:00
```
2020-06-25 21:11:21 -07:00
```xml
2020-02-03 22:13:06 -08:00
<?xml version="1.0" encoding="UTF-8"?>
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</CD>
<CD>
<TITLE>Hide your heart</TITLE>
<ARTIST>Bonnie Tyler</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>CBS Records</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1988</YEAR>
</CD>
...
2020-06-25 12:56:06 -07:00
```
2020-06-25 21:11:21 -07:00
```bash
2022-09-07 13:56:16 -07:00
cat cd_catalog.xml | jc -p --xml
2020-06-25 21:11:21 -07:00
```
2020-06-25 12:56:06 -07:00
```json
2020-02-03 22:13:06 -08:00
{
"CATALOG": {
"CD": [
{
"TITLE": "Empire Burlesque",
"ARTIST": "Bob Dylan",
"COUNTRY": "USA",
"COMPANY": "Columbia",
"PRICE": "10.90",
"YEAR": "1985"
},
{
"TITLE": "Hide your heart",
"ARTIST": "Bonnie Tyler",
"COUNTRY": "UK",
"COMPANY": "CBS Records",
"PRICE": "9.90",
"YEAR": "1988"
2020-06-25 12:56:06 -07:00
}
]
}
2020-02-03 22:25:30 -08:00
}
2020-02-03 22:13:06 -08:00
```
2020-02-04 21:46:52 -08:00
### YAML files
2020-06-25 21:11:21 -07:00
```bash
cat istio.yaml
2020-02-03 21:38:08 -08:00
```
2020-06-25 21:11:21 -07:00
```yaml
2020-02-03 21:38:08 -08:00
apiVersion: "authentication.istio.io/v1alpha1"
kind: "Policy"
metadata:
name: "default"
namespace: "default"
spec:
peers:
- mtls: {}
---
apiVersion: "networking.istio.io/v1alpha3"
kind: "DestinationRule"
metadata:
name: "default"
namespace: "default"
spec:
host: "*.default.svc.cluster.local"
trafficPolicy:
tls:
mode: ISTIO_MUTUAL
2020-06-25 12:56:06 -07:00
```
2020-06-25 21:11:21 -07:00
```bash
2022-09-07 13:56:16 -07:00
cat istio.yaml | jc -p --yaml
2020-06-25 21:11:21 -07:00
```
2020-06-25 12:56:06 -07:00
```json
2020-02-03 21:38:08 -08:00
[
{
"apiVersion": "authentication.istio.io/v1alpha1",
"kind": "Policy",
"metadata": {
"name": "default",
"namespace": "default"
},
"spec": {
"peers": [
{
"mtls": {}
}
]
}
},
{
"apiVersion": "networking.istio.io/v1alpha3",
"kind": "DestinationRule",
"metadata": {
"name": "default",
"namespace": "default"
},
"spec": {
"host": "*.default.svc.cluster.local",
"trafficPolicy": {
"tls": {
"mode": "ISTIO_MUTUAL"
}
}
}
}
]
```
2025-05-10 11:25:41 -07:00
© 2019-2025 Kelly Brazil