Ubuntu 16.04 Dynamic MOTD

If you have ever used Ubuntu Server prior to its newest release of 16.04, then you should be familiar with the dynamic MOTD. Previously, this is what is presented to the user in terminal when a log on occurs.
This feature is very nice as it will give you a quick look at useful information. Unfortunately, Ubuntu Server 16.04 does not include the dynamic MOTD by default in this release. First you will need to install some prerequisites and build the directory structure. To do so, run the following commands in terminal.

Once the above commands have been run, you can move on to populating the files you created. Below you can copy and paste.

Header (00-header)

System Information (10-sysinfo)

Once these files are populated with the above, you should now be able to logout and then log back in either using putty or on the console and you will be presented with something that looks like below.motd-ubuntu16

Did you find this article useful? Why not share it with your friends?

26 thoughts on “Ubuntu 16.04 Dynamic MOTD

  1. very nice guide, worked flawless for me on a 16.04-server, thank you very much for it. ๐Ÿ™‚

    but one thing stays, and is shown TWO times below the last line (local user…) and it is this bunch of text:

    “The programs included with the Ubuntu system are free software;
    the exact distribution terms for each program are described in the
    individual files in /usr/share/doc/*/copyright.

    Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
    applicable law.”

    i just dont know where it comes from. the only clue is that iยดm using a new user only for ssh-access, maybe theres something somewhere, but i just dont know where to look at… any hints?

        1. Take a look at /etc/update-motd folder and ensure there are no other files in there besides those listed in the article.

          1. i checked the files; its a fresh install following your instructions above. the dynamic-file contains only what your example will show. and more should not be printed at login. i found lots of similar postings, maybe pointing to a bug. dunno. basically its working correct the way you are describing it above. o.O

      1. Everything but the comments haha

        I do get failure saying there is no motd.dynamic to remove. However that shouldn’t be an issue. This isn’t a total loss on my current server, I just wanted to have it working so I can add the motd to future server when we get them off of 14.

  2. I’ve set this up on an LXD container and get the following error:

    :~# run-parts /etc/update-motd.d/

    /etc/update-motd.d//00-header: 24: /etc/update-motd.d//00-header: Syntax error: “&” unexpected
    run-parts: /etc/update-motd.d//00-header exited with return code 2
    System information as of: Fri Sep 16 11:32:29 UTC 2016

    System Load: 0.04 IP Address:
    Memory Usage: 3.3% System Uptime: 2 min
    Usage On /: 1% Swap Usage: 0.0%
    Local Users: 1 Processes: 23

    10 packages can be updated.
    0 updates are security updates.

    /etc/update-motd.d//90-footer: 24: /etc/update-motd.d//90-footer: Syntax error: “&” unexpected
    run-parts: /etc/update-motd.d//90-footer exited with return code 2

  3. Great write-up! I have a few suggestions. Since these scripts run upon each ssh connection it is important they run fast. “route” command by default performs DNS lookup/address resolution. This may be, and often is, slow and my be measured in full seconds. To avoid the annoying lag “-n” switch can be used. When doing that “grep” should be tweaked as well to search for “” instead of default. So the final snippet should look like “route -n | grep ‘^’ -m 1” where “-m 1” tells grep that there is no need to continue after the first matching line is found.

    Also both “route” and “ifconfig” are in /sbin directory which means that some environments (e.g. when executed by cron) which don’t have “/sbin” included in $PATH will not work. To make sure the scripts work they need to reference “/sbin/route” and “/sbin/ifconfig”.

  4. the free -m command displays differently on Ubuntu 16.04 and up than previous versions, which is why it always displays 0.0% memory and swap now.

    So on line 23 of 10-sysinfo it should be this I guess?:
    memory_usage=`free -m | awk ‘/Mem:/ { printf(“%3.1f%%”, $3/$2*100) }’`

      1. I am running a fresh install of 16.04.1 and everything is working as expected. Note, I have updated the sysinfo file to report the correct memory usage.

          1. I had been meaning to update the article anyhow, your first comment this morning just reminded me to do so. Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.