1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-08-08 22:36:48 +02:00

add examples

This commit is contained in:
Kelly Brazil
2019-11-15 09:29:54 -08:00
parent 6f67eecd5e
commit 3f1d3ff6d8
2 changed files with 73 additions and 6 deletions

View File

@ -70,6 +70,7 @@ jc PARSER [OPTIONS]
- `--dig` enables the `dig` parser - `--dig` enables the `dig` parser
- `--env` enables the `env` parser - `--env` enables the `env` parser
- `--free` enables the `free` parser - `--free` enables the `free` parser
- `--fstab` enables the `/etc/fstab` parser
- `--history` enables the `history` parser - `--history` enables the `history` parser
- `--hosts` enables the `/etc/hosts` file parser - `--hosts` enables the `/etc/hosts` file parser
- `--ifconfig` enables the `ifconfig` parser - `--ifconfig` enables the `ifconfig` parser
@ -378,6 +379,36 @@ $ free | jc --free -p
} }
] ]
``` ```
### /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
}
]
```
### history ### history
``` ```
$ history | jc --history -p $ history | jc --history -p

View File

@ -5,7 +5,33 @@ Usage:
Examples: Examples:
$ 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
}
]
""" """
import jc.utils import jc.utils
@ -24,15 +50,25 @@ def process(proc_data):
[ [
{ {
"ip": string, "fs_spec": string,
"hostname": [ "fs_file": string,
string "fs_vfstype": string,
] "fs_mntops": string,
"fs_freq": integer,
"fs_passno": integer
} }
] ]
""" """
for entry in proc_data:
int_list = ['fs_freq', 'fs_passno']
for key in int_list:
if key in entry:
try:
key_int = int(entry[key])
entry[key] = key_int
except (ValueError):
entry[key] = None
# no additional processing needed
return proc_data return proc_data