|
| 1 | +Summary |
| 2 | +======= |
| 3 | + |
| 4 | +sysmotd is essentially a shell script that produces a Message Of The Day |
| 5 | +(MOTD) including system information and statistics. |
| 6 | + |
| 7 | +It has been developed and tested on Fedora Linux and it might work on |
| 8 | +other Red Hat-based distributions with very small tweaks. It should also |
| 9 | +be relatively simple to port to other distributions that do not have |
| 10 | +their own dynamic MOTD generator. |
| 11 | + |
| 12 | +As of time of writting, Fedora only uses pam_motd.so for ssh log ins. |
| 13 | + |
| 14 | +How it looks like |
| 15 | +================= |
| 16 | + |
| 17 | +A picture is worth a thousand words. |
| 18 | + |
| 19 | +Background |
| 20 | +========== |
| 21 | + |
| 22 | +I am a long term Fedora user. Having worked with some Ubuntu servers |
| 23 | +lately, I found myself missing the system information and statistics |
| 24 | +that you get when you log in. When I installed Fedora 37 on a Raspberry |
| 25 | +Pi4, I saw that cockpit would generate a MOTD, and I decided to research |
| 26 | +a bit to find out if I could add my own message with some system statistics in |
| 27 | +it. |
| 28 | + |
| 29 | +Out of the various sources I found, I would like to give credit to a |
| 30 | +couple that helped me a lot in getting the information that I wanted and |
| 31 | +what tools to use. |
| 32 | + |
| 33 | +[1] https://github.com/angela-d/motd-for-centos |
| 34 | + |
| 35 | +[2] https://gist.github.com/cha55son/6042560 |
| 36 | + |
| 37 | +While those sources gave me a good start, I wanted to reduce the number |
| 38 | +of dependencies to a minimum and to make the dynamic part of the MOTD as |
| 39 | +efficient as possible. Hence I re-wrote re-wrote those and started |
| 40 | +looking into how to avoid using the user's profile to trigger the |
| 41 | +script. That leads us to the next section. |
| 42 | + |
| 43 | +Structure and how it works |
| 44 | +========================== |
| 45 | + |
| 46 | +My understanding is that Debian and Ubuntu distribute a patched version |
| 47 | +of pam_motd.so. Theirs runs scripts in /etc/update-motd.d. Also, their |
| 48 | +PAM configuration includes lines for static and dyanamic MOTDs. |
| 49 | + |
| 50 | +[3] https://wiki.debian.org/motd |
| 51 | + |
| 52 | +Using a patched version of pam\_motd.so would have been the preferred |
| 53 | +approach since the script updating the dynamic part of the MOTD would only |
| 54 | +run when a user logged in. However, I didn't know how difficult it would |
| 55 | +be to get a change like that approved for Fedora. My assumption was, and |
| 56 | +still is, that the people behind Fedora or Red Hat know that Debian and |
| 57 | +Ubuntu are using this dynamic MOTD approach and if they have not |
| 58 | +implemented it yet, it is because they have some valid reasons. |
| 59 | + |
| 60 | +Having made that assumption, I resorted to use a systemd service to call |
| 61 | +the script and a timer to call the service, every minute. However, not all the |
| 62 | +parts of the script that generate the corresponding part of the MOTD run |
| 63 | +every minute. |
| 64 | + |
| 65 | +So, sysmotd is comprised of: |
| 66 | + |
| 67 | +### /usr/libexec/sysmotd |
| 68 | + |
| 69 | +The shell script. It produces 3 files which are saved under |
| 70 | +/run/motd.d |
| 71 | + |
| 72 | +- 00-sysmotd-header.motd: colorful header that changes every 60 |
| 73 | + minutes. |
| 74 | +- 01-sysmotd-sysinfo.motd: system information which is updated every |
| 75 | + 60 seconds. |
| 76 | +- 02-sysmotd-updates.motd: updates available which is updated every 60 |
| 77 | + minutes. It uses Fedora's own dnf cache which runs whenever it runs. |
| 78 | + |
| 79 | +### /usr/lib/systemd/system/sysmotd.service |
| 80 | + |
| 81 | +A systemd service to run the script. It is disabled and it should stay |
| 82 | +like that. |
| 83 | + |
| 84 | +### /usr/lib/systemd/system/sysmotd.timer |
| 85 | + |
| 86 | +A systemd timer to run the service every 60 seconds. The script works |
| 87 | +out which parts of the MOTD to update. It is enabled and started when |
| 88 | +the dnf package is installed. |
| 89 | + |
| 90 | +### /usr/lib/systemd/system-preset/50-sysmotd.preset |
| 91 | + |
| 92 | +A systemd preset file to disable sysmotd.service and enable |
| 93 | +sysmotd.timer by default. |
| 94 | + |
| 95 | +In summary, what you get when you install sysmotd is a systemd timer |
| 96 | +that every 60 seconds runs a service, that runs a script, which in turn |
| 97 | +updates the header every 60 minutes, system's information every 60 |
| 98 | +seconds, and the updates available every 60 minutes too. |
| 99 | + |
| 100 | +How to install sysmotd and dependencies |
| 101 | +======================================= |
| 102 | + |
| 103 | +These are the Fedora packages that you need to have installed for |
| 104 | +sysmotd to work: |
| 105 | + |
| 106 | +bash |
| 107 | +coreutils |
| 108 | +dnf |
| 109 | +figlet |
| 110 | +findutils |
| 111 | +gawk |
| 112 | +lolcat |
| 113 | +procps-ng |
| 114 | +systemd |
| 115 | + |
| 116 | +Most systems will have all of them installed apart from figlet and |
| 117 | +lolcat. |
| 118 | + |
| 119 | +To install sysmotd and its dependencies, my recommendation is to |
| 120 | +download the rpm package under rpmbuild/RPMS/noarch in this repo, and |
| 121 | +install it with dnf. |
| 122 | + |
| 123 | + sudo dnf install sysmotd-0.0.1-1.fc37.noarch.rpm |
| 124 | + |
| 125 | +If you rather not install a package from an unknown source, and I |
| 126 | +wouldn't blame you for that, you can clone this repo and, after |
| 127 | +inspecting the files listed under the structure section, copy them to |
| 128 | +their respective folders. Please note that if you do this, and you are |
| 129 | +running selinux enforced, you will have to fix the context of the files. |
0 commit comments