5 ms·
Some notes from a FreeBSD user: > shell things (duplicating from other comments) Bash is indeed not in FreeBSD base; it's easy to install it, but not installi
by toast0 7y ago
Some notes from a FreeBSD user:
> shell things
(duplicating from other comments) Bash is indeed not in FreeBSD base; it's easy to install it, but not installing it is also a valid choice. The default login shell doesn't make a big difference, you can use chsh to change that. I also agree POSIX sh isn't quite enough for a lot of scripts.
> [ sysfs, procfs]
These are sort of available, but really just for compatibility with Linux binaries; take a look at the man pages for linsysfs and linprocfs. Just a note to say they're not totally missing, but I would agree they probably don't contain what you're looking for anyway.
> In some cases the sysctl output is not easily machine-parseable. For example, the uptime information from sysctl -n kern.boottime
Depending on how easy it is to process binary values, sysctl -b kern.boottime could be useful here; you'd get two raw integers.
> FreeBSD's netstat -I em0 -bin returns a tabular display,
You might try netstat -I re0 -bin --libxo json or similar. libxo was added in FreeBSD 11.0, and I think got plumbed to the networking commands at least (I see it's not hooked to sysctl in 12.0, so probably not in whatever 11.X pfSense is on either, although it would be useful). check man xo_parse_args for more details.
> nothing recognizes --help
--help is a GNUism; usually the BSD version is -h (although, not for netstat), and yeah, the included help text isn't super useful unless you know what the things mean... pfSense is intended for resource constrained systems, which I guess justifies no man text... but I'd install it it's possible, it's super useful.
> Perl would probably be another good choice
(this isn't accurate, as noted by comments) Perl is a nice choice on FreeBSD, because it is part of the base system (unlike, as you noted, bash). This can sometimes be a bit tricky, if you want a new perl feature, but as long as you're writing run of the mill perl (which everything described here should fit), as long as it's not a positively ancient system, you should be ok.
Anyway; it looks like you've learned quickly; enjoy!
- Arnavion 7y agoThank you. I'll try out the `sysctl -b` and `netstat --libxo` methods tonight.
- Arnavion 7y ago`sysctl -b kern.boottime` works wonderfully. The output is two 64-bit integers, so the script pipes it through `od -t uI`. I would've liked to use `-t uL` but `od` complains that it's a "bad byte count", so the script has to manually add the two components together. (`-t dL` also raises the same error, even though the man page implies that at least should work. Strange. I did not investigate why.) It also works for the thermal sysctls - they appear to output 4-byte unsigned integers in deci-Kelvins. Eg 3061 is 306.1 K == 33.0 degrees Celsius. `netstat ... --libxo json` does work, though parsing JSON from awk isn't trivial either. The best way I can think of is to use `json,pretty` which puts one key-value-pair per line, which I could then filter for the specific keys I want. But it would amount to as much or more effort as the non-JSON parser makes. pfSense doesn't have `jq` by default but does have `uclcmd`. I got as far as `netstat -I em0 -bin --libxo json | uclcmd get -f - -j '.statistics.interface'` to get an array of JSON objects, but any attempt to apply a transformation to each element of this array (there are no manpages for it online, but its Github readme implies the existence of an `each` function) caused the program to segfault.
- takeda 7y agoAFAIK Perl is now optional and is not in the base. There was effort to make all system components to not depend on any dynamic language.
- inferiorhuman 7y agoIn some cases the sysctl output is not easily machine-parseable. For example, the uptime information from sysctl -n kern.boottime This largely misses the point. The output of sysctl(8) is not intended to be machine readable. Instead of parsing strings you should be using sysctl(3) directly or through whatever bindings for your language of choice.
- toast0 7y agoI don't believe POSIX shell or awk have bindings for sysctl(3)?
- inferiorhuman 7y agoI don't believe POSIX shell or awk have bindings for sysctl(3)? That's essentially what sysctl(8) is. Unlike Linux though the text interface isn't really intended to be the primary API. The article discusses using Rust and C which both have access to sysctl(3).
- Arnavion 7y agoYes, now that I realize `sysctl -b` exists, I've retracted that part of the blog post.
- petre 7y agoPerl hasn't been part of the base system since FreeBSD 8 or so. It's also fairly recent, 5.26 I think, whereas the current one is 5.30 (even minor versions numbers are stable). Also pfSense is a constrained environment wothout all the feature of a full FreeBSD install.
- RJIb8RBYxzAMX9u 7y ago>> nothing recognizes --help > --help is a GNUism; usually the BSD version is -h (although, not for netstat), and yeah, the included help text isn't super useful unless you know what the things mean... OTOH, FreeBSD's man pages[0] are superb compared to that of Linux for most subjects. I usually don't bother with -h and go straight to the man pages. [0] https://www.freebsd.org/cgi/man.cgi https://www.freebsd.org/cgi/man.cgi
- tedunangst 7y ago-? Should print usage for just about everything.