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.
...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:
> 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.
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.
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.
* If one is going to have a Linux/FreeBSD/Solaris split, one needs to apply it to section 1. "lsbrelease" is a Linux-based operating system only command.
* Debian now includes /etc/os-release . Interestingly, so too does DragonFlyBSD (but not FreeBSD).
* "last reboot" has been supposedly superseded in systemd operating systems, by "journalctl -b".
* Not even everyone has /var/log/messages any more, or /var/log/warn . Even Debian has, just last month, made the systemd journal its primary on-disc storage.
* Use "vipw" to avoid having to remember to recompile master.passwd . It respects $EDITOR .
* The ps flags are 30 years out of date for the BSDs. BSD switched ps to use getopt() at the start of the 1990s, and they've officially started with a minus sign all of that time since.
* The better trace program on FreeBSD, and the only one on OpenBSD, is the original BSD ktrace/kdump .
In section 3:
* FreeBSD partitioning is done with "gpart".
I stopped there. There are probably some howlers under installation and shells, given how outdated some of the other stuff was. Debian and Ubuntu changed /bin/sh to the Debian Almquist shell a decade and a bit ago. FreeBSD replaced pkg with pkg-ng in version 9. These are two very common errors that I see.
26 comments
[ 1.7 ms ] story [ 73.5 ms ] thread2010: https://news.ycombinator.com/item?id=1411075
:prayer hands emoji here:
[1] - https://github.com/kellyjonbrazil/jc
LANG=en jc df
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.
> 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.
I feel one might be tricked into believing this is a more sensible or stable than awk/sed.
-o json OR -o json-pretty
Pass --json for JSON output.
One word: anyone know why it Firefox mobile can't scale the page text up? No issue on Brave/Chrome mobile.
From section 1:
* "man hier" is out of date, alas. https://unix.stackexchange.com/a/567405/5132
* If one is going to have a Linux/FreeBSD/Solaris split, one needs to apply it to section 1. "lsbrelease" is a Linux-based operating system only command.
* Debian now includes /etc/os-release . Interestingly, so too does DragonFlyBSD (but not FreeBSD).
* "last reboot" has been supposedly superseded in systemd operating systems, by "journalctl -b".
* "atacontrol" was superseded by "camcontrol" in FreeBSD back in 2012. https://www.freebsd.org/releases/9.0R/relnotes-detailed.html...
* Not even everyone has /var/log/messages any more, or /var/log/warn . Even Debian has, just last month, made the systemd journal its primary on-disc storage.
* Use "vipw" to avoid having to remember to recompile master.passwd . It respects $EDITOR .
* Most Linux operating systems do not use run levels at all now. http://jdebp.uk./FGA/run-levels-are-history.html
In section 2:
* The ps flags are 30 years out of date for the BSDs. BSD switched ps to use getopt() at the start of the 1990s, and they've officially started with a minus sign all of that time since.
* The better trace program on FreeBSD, and the only one on OpenBSD, is the original BSD ktrace/kdump .
In section 3:
* FreeBSD partitioning is done with "gpart".
I stopped there. There are probably some howlers under installation and shells, given how outdated some of the other stuff was. Debian and Ubuntu changed /bin/sh to the Debian Almquist shell a decade and a bit ago. FreeBSD replaced pkg with pkg-ng in version 9. These are two very common errors that I see.