2021-04-09 10:36:42 -07:00
|
|
|
[Home](https://kellyjonbrazil.github.io/jc/)
|
2022-01-25 17:07:47 -08:00
|
|
|
<a id="jc.parsers.sysctl"></a>
|
2020-07-30 16:20:24 -07:00
|
|
|
|
2020-07-09 16:18:33 -07:00
|
|
|
# jc.parsers.sysctl
|
2022-01-25 17:07:47 -08:00
|
|
|
|
2022-03-04 13:27:39 -08:00
|
|
|
jc - JSON Convert `sysctl -a` command output parser
|
2020-08-05 16:51:58 -07:00
|
|
|
|
2022-01-19 17:30:14 -08:00
|
|
|
Note: Since `sysctl` output is not easily parsable only a very simple
|
2022-01-25 18:03:34 -08:00
|
|
|
key/value object will be output. An attempt is made to convert obvious
|
|
|
|
integers and floats. If no conversion is desired, use the `-r`
|
|
|
|
command-line argument or the `raw=True` argument in `parse()`.
|
2020-07-09 16:18:33 -07:00
|
|
|
|
2020-08-05 13:32:59 -07:00
|
|
|
Usage (cli):
|
2020-07-09 16:18:33 -07:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
$ sysctl -a | jc --sysctl
|
2020-08-05 16:51:58 -07:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
or
|
2020-07-09 16:18:33 -07:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
$ jc sysctl -a
|
2020-07-09 16:18:33 -07:00
|
|
|
|
2020-08-05 13:32:59 -07:00
|
|
|
Usage (module):
|
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
import jc
|
|
|
|
result = jc.parse('sysctl', sysctl_command_output)
|
2022-01-18 15:38:03 -08:00
|
|
|
|
2021-04-08 15:52:49 -07:00
|
|
|
Schema:
|
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
{
|
|
|
|
"key1": string/integer/float, # best guess based on value
|
|
|
|
"key2": string/integer/float,
|
|
|
|
"key3": string/integer/float
|
|
|
|
}
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
$ sysctl -a | jc --sysctl -p
|
|
|
|
{
|
|
|
|
"user.cs_path": "/usr/bin:/bin:/usr/sbin:/sbin",
|
|
|
|
"user.bc_base_max": 99,
|
|
|
|
"user.bc_dim_max": 2048,
|
|
|
|
"user.bc_scale_max": 99,
|
|
|
|
"user.bc_string_max": 1000,
|
|
|
|
"user.coll_weights_max": 2,
|
|
|
|
"user.expr_nest_max": 32
|
|
|
|
...
|
|
|
|
}
|
|
|
|
|
|
|
|
$ sysctl -a | jc --sysctl -p -r
|
|
|
|
{
|
|
|
|
"user.cs_path": "/usr/bin:/bin:/usr/sbin:/sbin",
|
|
|
|
"user.bc_base_max": "99",
|
|
|
|
"user.bc_dim_max": "2048",
|
|
|
|
"user.bc_scale_max": "99",
|
|
|
|
"user.bc_string_max": "1000",
|
|
|
|
"user.coll_weights_max": "2",
|
|
|
|
"user.expr_nest_max": "32",
|
|
|
|
...
|
|
|
|
}
|
2022-01-25 17:07:47 -08:00
|
|
|
|
|
|
|
<a id="jc.parsers.sysctl.parse"></a>
|
|
|
|
|
2022-03-05 12:15:14 -08:00
|
|
|
### parse
|
2022-01-25 17:07:47 -08:00
|
|
|
|
2020-07-09 16:18:33 -07:00
|
|
|
```python
|
2022-01-25 17:07:47 -08:00
|
|
|
def parse(data, raw=False, quiet=False)
|
2020-07-09 16:18:33 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
Main text parsing function
|
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
Parameters:
|
2020-07-09 16:18:33 -07:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
data: (string) text data to parse
|
|
|
|
raw: (boolean) unprocessed output if True
|
|
|
|
quiet: (boolean) suppress warning messages if True
|
2020-07-09 16:18:33 -07:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
Returns:
|
2020-07-09 16:18:33 -07:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
Dictionary. Raw or processed structured data.
|
2020-07-09 16:18:33 -07:00
|
|
|
|
2022-01-25 19:18:54 -08:00
|
|
|
### Parser Information
|
2021-04-09 10:36:42 -07:00
|
|
|
Compatibility: linux, darwin, freebsd
|
|
|
|
|
2021-12-01 16:12:51 -08:00
|
|
|
Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com)
|