Would you allow me to optimize your commands a little bit?
/usr/sbin/pkg version | grep -v = |wc -l
/usr/sbin/pkg version -L= | wc -l
ifconfig | grep inet | grep -v inet6 |grep -v 'inet 127' | awk '{print $2}'
ifconfig | awk '$1 == "inet" && $2 !~ /^127/ {print $2}'
It always hurts my eyes when I see a long pipe with several grep commands, followed by abusing awk to just cut one row. awk can do
much more than just
print $X
. In this particular case, it saves three fork/exec, three pipes and three instances of grep.
Back on the topic of MOTD itself: I once replaced
/etc/motd with a named pipe (a.k.a. FIFO, see
mkfifo(1)) and attached a simple daemon to it (in fact a shell script running as a daemon) that feeded information into the pipe dynamically. Every time someone logged in, he got up-to-date information about several system parameters, including the amount of free space on the /home partition and things like that. You can have a similar effect with a cron job that rewrites
/etc/motd every five minutes or whatever, but I like the FIFO solution much better. For security I created a special user for that purpose who is allowed to write to the FIFO, and run the daemon with that user ID, so no root privileges are required.
Finally, here is a nifty little
sed(1) script, it's just one line:
#!/usr/bin/sed g;r /etc/motd
Save that as
motd
and chmod 755 it, then you can simply type
motd
and it will display the MOTD. Of course you can do the same with
alias motd="cat /etc/motd"
(or similar syntax, depending on the shell), but the above script works independent of the shell. Apart from that, many people are surprised that you can actually write pure sed scripts, and I like to surprise people. ;-)