8 ms·
Local Linux User Tries FreeBSD
- lwb 7y ago> I decided to write a script that would repeatedly flash the LED on the Pi in morse code corresponding to its current IP address I wish my day job was this exciting!
- mikece 7y agoAnd are you reading that visually in Morse code? I would have thought a different/more optimized flashing pattern that required a smartphone to read would be faster, especially if we're talking IPv6 addresses, but that's just me.
- Arnavion 7y agoYes. I made it flash 100ms-on-900ms-off for a ZERO, and 500ms-on-500ms-off for a ONE. There's a 1000ms-on-1000ms-off flash at the beginning to indicate the start point. And it's IPv4, so there's only 32 bits. So it's slow enough to read out and type out into a text editor, then convert the typeout to its IP, but not slow enough that it's a bother.
- thedanbob 7y agoThat was the part that really jumped out at me as well. I've had the same problem before and this is a genius solution.
- agapon 7y agoI feel compelled to point out that FreeBSD manual page for the led driver has this example: /usr/bin/morse -l "Soekris rocks" > /dev/led/error Guess what it does :-)
- throw0101a 7y agoFor those curious: * https://www.freebsd.org/cgi/man.cgi?query=led&sektion=4 https://www.freebsd.org/cgi/man.cgi?query=led&sektion=4 * https://www.freebsd.org/cgi/man.cgi?query=morse&sektion=6 https://www.freebsd.org/cgi/man.cgi?query=morse&sektion=6
- juped 7y agoMore accurate title: Local Linux user discovers awk is a great and portable tool for handling structured text (it is)!
- Arnavion 7y agoI did discover one minor bit of non-portability. To show the 10 most recent firewall log entries, the dashboard runs `clog filter.log | tail -10r` (`tail -10r` is the equivalent of `tail -10 | tac`). It would be nice to instead just run `clog -f filter.log` (open filter.log in follow mode, just like `tail -f`), leave it open across dashboard refresh iterations, and maintain an in-memory buffer of the 10 most recent entries for display. It would presumably be more efficient. However this requires the ability to do a non-blocking read of the command output, which requires `PROCINFO["read_timeout"]`, which is gawk-specific and not available on FreeBSD's default awk. I don't mind it too much, because repeatedly doing `clog -f | tail -10r` doesn't use that much CPU to be concerned about anyway. Though I may investigate Perl to see if it's possible there.
- acqq 7y agoI guess you mean something like (in Perl): while (1) { try_reading_one_more_line( $file_in ); print_last_10_lines_reverse(); sleep( 1 ); # wait, in this case one second } and that doing on the opened file $file_in. You'd have to write both functions in the loop of course. But Perl is a real language which allows you to try reading from the point in the file you've reached the last time, without reading anything you've already read again. POSIX semantics allows you to observe that the file grew even if in the previous pass you've hit the end of file. And you even don't have to keep in memory the lines which aren't to be printed anymore. I prefer Perl to any shell scripts, as soon as the script is more than circa 10 lines.
- Arnavion 7y ago>I guess you mean something like Yes. >But Perl is a real language which allows you to try reading from the point in the file you've reached the last time, without reading anything you've already read again. The input in this case is the stdout of a command (clog), so it's not a seekable file.
- rhinoceraptor 7y ago> I decided to write a script that would repeatedly flash the LED on the Pi in morse code corresponding to its current IP address Wouldn't it be a lot easier to use mdns/zeroconf, or static IPs? Or use a label maker and put the MAC address on it, and then use arp-scan?
- Arnavion 7y agoIt was mostly just a fun thing I decided to do to flex my newly-acquired awk skills.
- pbhjpbhj 7y agoIs Morse ab efficient way to present dotted-quads, it doesn't seem like it would be?
- Arnavion 7y agoThe code is what I described in https://news.ycombinator.com/item?id=21567202 https://news.ycombinator.com/item?id=21567202 . It's equivalent to first converting 0 to E and 1 to T, then transmitting that. It's not using the representations of 0 and 1 themselves, which are five times longer.
- rhinoceraptor 7y agoI didn't mean for it to sound dismissive, it's definitely a neat idea.
- smacktoward 7y agoYou don't get many nerd points for knowing how to use a label maker :-D
- MuffinFlavored 7y ago> The default FreeBSD shell is tcsh. I was prepared to not have bash, but tcsh is quite alien in its syntax compared to regular POSIX sh. I decided to ignore it and just use POSIX sh. Would FreeBSD consider POSIX sh as their default shell instead of tcsh?
- toast0 7y agoYou can easily change your login shell with chsh. If you install bash first, you can change your shell to bash. It's an inconvenience to change it, but changing the default is a major effort.
- JoshTriplett 7y agoFreeBSD wouldn't select a default shell that uses the GPL, but using a simple POSIX shell as the default would make sense.
- toast0 7y agoPOSIX sh is a sensible default; and the technical work to do it would take less time than we've spent writing these comments. However, actually changing the default, would be a major effort; you'd need to form a consensus that the new default is better than the old default, that it's so much better than the old default that invalidating any documentation that relies on the old default is worth it.
- anthk 7y agoksh is not GPL and it's much better than csh.
- pgib 7y agoNote that if you do this, you should either `pkg install bash-static` or build bash from the ports using STATIC option (I don't _believe_ it's the default, though it really should be). Without that static option, you could potentially break your shell by upgrading related packages.
- 7y ago
- jlg23 7y ago> The default FreeBSD shell is tcsh. I was prepared to not have bash, but tcsh is quite alien in its syntax compared to regular POSIX sh. All FreeBSD scripts I encountered use posix shell. > does have a dependency on perl to get the current time in seconds from the Unix epoch. This is because FreeBSD's date does not have a way to get milliseconds in the time One could just install the GNU coreutils (probably, not checked though, much less overhead than a full perl install) or kill that problem with very few lines of C.
- Arnavion 7y agoYes, I would've done that for a regular FreeBSD install. But as I wrote a little before that part, because it was a pfSense install, I decided not to install any additional `pkg` packages myself.
- Lammy 7y agoYou could use a kqueue timer to run your script once per second: https://wiki.netbsd.org/tutorials/kqueue_tutorial/#index4h2 https://wiki.netbsd.org/tutorials/kqueue_tutorial/#index4h2
- AdamN 7y agoGNU coreutils are also available (and useful) on MacOS.
- michaelsbradley 7y agobrew install bash coreutils findutils gawk parallel
- JoshTriplett 7y ago> All FreeBSD scripts I encountered use posix shell. Defaults matter, and it's helpful when the default shell for command-line use matches the shell used for scripting, because people often do scripting on the command line.
- 7y ago
- boomboomsubban 7y ago>DuckDuckGo would not return that URL when searching for, say, freebsd man netstat !man netstat
- Arnavion 7y agoTIL. Thank you.
- toast0 7y agoSome 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.
- superkuh 7y agoI love that you can comment by sending an email with the title of the post in the subject. >You can post comments on this blog post by: sending mail to email@address.dev with a subject starting with [blog-2019-10-20-local-linux-user-tries-freebsd]
- jdofaz 7y agoWould be fancier if it was a mailto link with the subject already populated
- kevin_thibedeau 7y agoSpammers would hammer it with bots.
- 1996 7y agoI wonder how it work. Is there an exim/postfix extension to do that? Or is it done from the mbox?
- tedunangst 7y agoluajit makes it pretty easy to call arbitrary sysctl and ioctl functions. You can start with popen to some command, then when that's slow, switch to ffi calls.
- doc1623 7y agoI used to use Freebsd. It was great until it wasn't. Mainly, I would recommend not using it as a desktop. It's perfect for a server or FreeNAS but the ports for common desktop applications seem to be broken fairly often which causes usability issues and some very heavy frustration. From the forums (you will use them allot), I learned that the developers mainly use Macs as their primary PC's. So this problem is not likely to change. As far as Awk over Perl. It's been quite some time but when I did awk scripts they had some pretty annoying quirks that you just had to learn. Perl was just easier. Has that changed? I know that Perl as a larger language is languishing but isn't it still perfect for this type of thing?
- bachmeier 7y ago> It's perfect for a server or FreeNAS but the ports for common desktop applications seem to be broken fairly often which causes usability issues and some very heavy frustration. I briefly tried FreeBSD. Only briefly, because that ports thing was a mess. My trial lasted only a few days before my system was an unusable mess.
- doc1623 7y agoPart of that is, it's just a fairly steep learning curve. I did learn to stick with one way of doing ports. I used Portmaster then you learn not to troubleshoot too much as you can really make a mess of things. You need to let the tools work for you, but again... when the ports themselves are broken (i.e. not your machine/dependency .."heck") then you can't do anything.
- throw0101a 7y ago> Only briefly, because that ports thing was a mess. In what way was it a mess?
- simonblack 7y agoFor the 'best of both worlds' scenario, use Slackware Linux in place of FreeBSD. Slackware is one of the very oldest Linuxes, and traditionally used a BSD-flavored 'init' system, rather than a System-V syle init, or even the newer 'systemd'. It has traditionally concentrated on being extremely stable, and more slanted towards server work, though I used it for many years as my main desktop.
- lightbulbjim 7y agoI would say it's more slanted towards desktop use than server use. Generally you want to automate server management with some sort of config management. While possible with Slackware, it's easier with a Debian or Red Hat style system. For a desktop Slackware is pretty nice. It's easy to understand and gets out of your way. I used it for over a decade until, one day, I realised I was tired of recompiling slackbuilds after each low level dependency upgrade.
- musicale 7y agoMy brain immediately filled in the imaginary clickbait headline: Local Linux User Tries FreeBSD - You Won't Believe What Happens Next! (Actually nothing much happened at all. A few differences, but nothing major.)