Can I put shell commands in the /etc/motd
login banner file? I have tried:
$(uptime)
and
`uptime`
Is this possible?
Can I put shell commands in the /etc/motd
login banner file? I have tried:
$(uptime)
and
`uptime`
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 packagelibpam-modules
: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. Note however that this approach has been also used byupdate-motd
, but it has been abandoned because of problem encountered. You can find a bit more info about this here.For Centos 7 servers I suggest using my port of
update-motd.d
from Ubuntu.Unlike other solutions it makes the dynamic MOTD actually show only once, when you SSH / login through a console (other solutions make it show when you open new
screen
windows, for example).Install it with:
Use with:
/etc/motd
.PrintMotd no
,Banner none
,UsePAM yes
(and optionallyPrintLastLog no
) in your/etc/ssh/sshd_config
& reloadsshd
service./etc/pam.d/sshd
:session optional pam_motd.so motd=/run/motd.dynamic
./etc/update-motd.d
, like on UbuntuPlease see https://github.com/gdubicki/centos-pam-with-update-motd for the most up to date info.