News for hackers. Stuff that matters.
Re:Unix Toolbox (2008) by MichaelMoser123 on Friday February 21, 2020 @07:05AM (#22382513)
Is there a tool that returns linux system information in json format, that works for most kernel versions and / is actively supported? i think it would be easier to pipe through jq in order to get a desired value, rather then pipe through grep/awk/sed.
Re:Unix Toolbox (2008) by bkq on Friday February 21, 2020 @07:21AM (#22382562)
There's jc [1], that can return the JSON output of standard Linux CLI tools.

[1] - https://github.com/kellyjonbrazil/jc

Re:Unix Toolbox (2008) by tjoff on Friday February 21, 2020 @09:03AM (#22383123)
The answer to 'who would parse the result of ls' is answered in the first example of the readme.

I feel one might be tricked into believing this is a more sensible or stable than awk/sed.

Re:Unix Toolbox (2008) by fizixer on Friday February 21, 2020 @08:53AM (#22383057)
Off-topic: Whenever I start thinking about json (or xml) I get lost in the turtle tower of metadata.

Like 'jc ls' gives json output with following entry format: { "filename": "[actual-filename-string]" }

Then I start asking: why not simply { "[actual-filename-string]" } ?

But then why stop at keyword value pairs? Why not:

{ "keyword": "filename", "value": "[actual-filename-string]" }

But then why not:

{ { "metakeyword": "keyword", "metavalue": "filename" }, { "metakeyword": "value", "metavalue": "[actual-filename-string]" } }

And so on.

Surely I can't be the only one. Would love to have this discussed, where to draw the line (and why), what's the utility, and so on.

Re:Unix Toolbox (2008) by msla on Friday February 21, 2020 @09:41AM (#22383431)
> Like 'jc ls' gives json output with following entry format: { "filename": "[actual-filename-string]" }

> Then I start asking: why not simply { "[actual-filename-string]" } ?

Because the first at least has a stab at being self-documenting, and maybe even forwards- and backwards-compatible: The file is saying what the values are (unless you're kinda dumb when choosing keys) and, since programs can ask for values by name, older programs won't have to deal with keys added by newer versions and newer programs can deal with missing values more gracefully than abandoning a whole parse because the record has six values instead of ten.

> But then why not:

> { { "metakeyword": "keyword", "metavalue": "filename" }, { "metakeyword": "value", "metavalue": "[actual-filename-string]" } }

Same information, now more verbose. Is there ever going to be a key other than "metakeyword" in that slot? If not, drop it.

Re:Unix Toolbox (2008) by Xophmeister on Friday February 21, 2020 @09:26AM (#22383299)

    { "[actual-filename-string]" }
...isn't valid JSON. As for going up the metatower, my personal take on this would be to strive for brevity. That is, what's the least structure we can get away with to unambiguously serialise what is needed? In most(?) cases, this is probably best:

    { "filename": "whatever", "foo": "bar", "etc": "etc" }
However, maybe there are instances where:

    [
      { "attribute": "filename", "value": "whatever" },
      { "attribute": "foo", "value": "bar" },
      { "attribute": "etc", "value": "etc" }
    ]
...is more appropriate. If, for example, you need to encode a flexible schema, rather than a fixed one.
Re:Unix Toolbox (2008) by swiley on Friday February 21, 2020 @04:36PM (#22387048)
If brevity is what you want then what’s wrong with the default field record ls output? It’s even a regular language!
Re:Unix Toolbox (2008) by dejj on Friday February 21, 2020 @09:19AM (#22383248)
For a related discussion, see "Evolution of a Haskell Programmer": https://willamette.edu/~fruehr/haskell/evolution.html
Re:Unix Toolbox (2008) by dejj on Friday February 21, 2020 @08:32AM (#22382910)
This is neat. Set your locale to English for parsers to work:

LANG=en jc df

Re:Unix Toolbox (2008) by de_watcher on Friday February 21, 2020 @07:28AM (#22382590)
Oh, that "easier" is very much a matter of preference. For me jq/yq is long syntax, slow execution, needs installation, format of the numbers is questionable. Netplan with its yaml config made into the mainstream, so there is hope that problems will be addressed because of friction it and similar subsystems create.
Re:Unix Toolbox (2008) by robmccoll on Friday February 21, 2020 @03:04PM (#22386223)
I realize this doesn't give you JSON, but if the goal is to retrieve information with little-to-no parsing, /etc/os-release defines everything in environment variable format. You can just source it and then use the environment variables directly for distro info.
Re:Unix Toolbox (2008) by jhoechtl on Friday February 21, 2020 @07:29AM (#22382593)
Output of systemd can be configured to return JSON:

-o json OR -o json-pretty

Re:Unix Toolbox (2008) by arminiusreturns on Friday February 21, 2020 @04:08PM (#22386759)
I was going to say this has come in very handy when shipping from systemd to syslog type parsers.
Re:Unix Toolbox (2008) by aepiepaey on Friday February 21, 2020 @09:49AM (#22383486)
There's facter (used by and developed for Puppet): https://github.com/puppetlabs/facter

Pass --json for JSON output.