GRABCONSOLE(8)

πŸ“¦ version 2024.12.07, in nixpkgs unstable

πŸ’– GRABCONSOLE(8) β€” the grabconsole program πŸ’–

okay bestie, welcome to the grabconsole page. It’s short, it’s powerful, it’s giving tiny-but-mighty utility energy ✨

🌸 SYNOPSIS 🌸

grabconsole file [command ...]

✨ DESCRIPTION ✨

So grabconsole redirects messages to /dev/console to the given file, and that file must be the slave side of a pseudoterminal. No cap. It may be specified as either a filename or a file descriptor. Then it execs the given command, if any. Slay.

This is useful to log such messages to disk when syslogd is not running but some services log through syslog. Literally the exact save.

πŸŽ€ EXAMPLE πŸŽ€

Here’s the vibe:

$ cat /service/console-log/run
#!/bin/sh
exec \
ptyget \
sh -c '
exec 6<&- 7<&- &&
setblock +4 &&
grabconsole 5 &&
exec <&4 \
setuidgid loguser \
multilog t ./main'

Break it down, bestie:

  • ptyget allocates a pseudoterminal.
  • setblock sets the master side to be blocking β€” so a process reading the master side will wait for input instead of getting EAGAIN when there is currently no input to be read. That’s the whole point, periodt.
  • grabconsole redirects /dev/console messages to the slave side of the pseudoterminal.
  • multilog, running as loguser, reads console messages from the master side of the pseudoterminal and writes them to ./main.
⚠️ note note note: this may cause problems with console logins unless logins use a different device referring to the console, such as /dev/tty1 on Linux. So like, be aware πŸ’€

πŸ¦‹ XCONSOLE VIBE πŸ¦‹

This line:

xterm -e sh -ec 'grabconsole 0; setblock +0; exec cat'

is equivalent to xconsole. That’s it. That’s the equivalence. Iconic.


πŸ’œ sign-off πŸ’œ

Source/version and date check: the footer is literally The grabconsole program() β€” no version number, no date, just mysterious minimal queen behavior. Byeee bestie, go redirect some console messages 🫢✨

πŸ“¦ where this page comes from