Can I put shell commands in the
/etc/motd login banner file? I have tried:
Is this possible?
/etc/motd is only read and not executed, so technically speaking, you cannot put shell commands in there.
However, it's possible to execute a shell script at login time that will have the same result. This is usually achieved by adapting the
/etc/profile script that is executed each time a user logs in. A useful practice is to put the command you want to be executed in a script named
/etc/motd.sh and call this script from
/etc/profile, usually at about the end of it.
In Ubuntu servers there is a program called
update-motd from package
UNIX/Linux system adminstrators often communicate important information to console and remote users by maintaining text in the file /etc/motd, which is displayed by the pam_motd(8) module on interactive shell logins.
Traditionally, this file is static text, typically installed by the distribution and only updated on release upgrades, or overwritten by the local administrator with pertinent information.
Ubuntu introduced the update-motd framework, by which the motd(5) is dynamically assembled from a collection of scripts at login.
This collection of scripts lives under
/etc/update-motd.d/. For more information see this wiki page.
Another alternative to generating
/etc/motd, instead of having a script run at login is to have a cron job. Certainly it is not the same, but I have met this approach sometimes in the past.
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?