# Customized MOTD



## Phishfry (Feb 12, 2019)

Well I am trying to get MOTD to show some machine information instead of standard MOTD.

Starting with packages I came up with this to see number of out of date packages:
`/usr/sbin/pkg version | grep -v = |wc -l`

Next up showing machine IP. Any suggestions? Should I grep `ifconfig` or /var/db/dhleases ??
`ifconfig | grep inet | grep -v inet6 |grep -v 'inet 127' | awk '{print $2}'`

I would like to see your custom MOTD. Please give me some ideas.


----------



## Deleted member 30996 (Feb 12, 2019)

```
FreeBSD 11.2-RELEASE-p9 (GENERIC) #0: Tue Feb  5 15:30:36 UTC 2019

                 Unauthorized Access Denied!!!
                           ,          ,
                          /(          )\
                          \\ \\___   / /
                          /- _  `-/  ' !
                          (/\\/ \\ \\   /
                          / /   | `    \
                          O O   ) /    |
                         `-^--'`<     '
                        (_.)  _  )   /
                         `.___/`    /
                           `-----' /
              <----.     __ / __   \\
              <----|====O)))==) \\) /====
              <----'    `--' `.__,' \\
                            |        |
                            \\       /
                      ______( (_  / \\______
                    ,'  ,-----'   |        \\
                    `--{__________)        \\/
```


----------



## olli@ (Feb 12, 2019)

Would you allow me to optimize your commands a little bit?


Phishfry said:


> `/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. ;-)


----------



## SirDice (Feb 12, 2019)

Mine are generated by Puppet. It shows some basic information like hostname, OS version, lifecycle environment (RHEL environment) and assigned Puppet role.


----------



## Phishfry (Feb 13, 2019)

This is my starting list:

```
date

cpuinfo:sysctl -a | grep hw.model

number of cpu:sysctl -a | grep hw.ncpu

installed memory:sysctl hw.physmem

camcontrol devlist

df -h

w

mount

echo "Last time freebsd-update ran:"

echo "Number of packages out of date:"; `/usr/sbin/pkg version | grep -v = |wc -l'

echo "Active SSH connections:"; netstat -p tcp | grep ssh

history 10
```


----------



## SirDice (Feb 13, 2019)

These might be useful:
`ifconfig -l -u inet` lists interfaces that are up and have an IPv4 address.
`ifconfig -l -u inet6` lists interfaces that are up and have an IPv6 address.


----------



## olli@ (Feb 13, 2019)

getopt said:


> It always hurts my eyes when I see a long command that could be shorter:
> 
> `ifconfig | awk '/inet/ && ! /^127/ {print $2}'`


That one doesn't work, though. Have you actually tried it? Neither does it remove the “inet6” lines, nor does it remove the loopback addresses.


----------



## NapoleonWils0n (Feb 13, 2019)

Very disappointed i thought Freebsd was going to let me customize Match of the Day,
and let my team Newcastle win for a change, by hacking the var system so all the shoots where over the line


----------



## Phishfry (Feb 13, 2019)

Thanks everyone for your suggestions.
This comment from a redddit post made me rethink using MOTD for a status blurb.


> I would think a script that's called by your .login shell script would be a better / easier way to do that.
> Your exercise isn't a bad way to poke around, but motd really isn't designed for that sort of thing. It's more for a "notice" or emergency alert or acknowledgement of responsibility type of thing that is manually updated.


----------

