brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Ubuntu runs your scripts in /etc/update-motd.d at every login

Ubuntu
~/tips/tip-ubuntu-update-motd-script

sudo tee /etc/update-motd.d/60-disk >/dev/null <<'EOF'

Add your own status lines to the message shown when you log in.

The text you see after an SSH login on Ubuntu is built by small scripts. You can add one of your own and put what you care about right in front of you.

Create a script with a two digit number that sets its position, and no file extension:

sudo tee /etc/update-motd.d/60-disk >/dev/null <<'EOF'
#!/bin/sh
echo
df -h / | tail -n 1 | awk '{print "Root disk used: " $5 " of " $2}'
EOF
sudo chmod +x /etc/update-motd.d/60-disk

Test all scripts without logging in again:

run-parts /etc/update-motd.d/

The scripts need to be executable and write to standard output. To silence one of the stock messages, remove its executable bit with chmod -x.

I like one or two lines at most, such as disk space or a pending reboot, because a wall of text at login gets ignored within a week.

Take care: according to the man page these run as root at each login. Never let a script execute something from a folder that other users can write to, and keep it quick. A slow command or a network call delays every login, so cache the result in a file if it takes more than a moment. A script with a syntax error just prints its complaint to whoever logs in.

Further reading: update-motd man page

More Ubuntu tips sudo apt install ppa-purge grep ^Prompt /etc/update-manager/release-upgrades ubuntu-bug openssh-server sudo update-alternatives --config editor pro status All Ubuntu tips (8) All topics

Link