/etc/motd is not displayed for non-interactive login

Latest response

when i login to the the terminal via putty i get the message of the day displayed ok.
but if im already logged on to my console using gnome and right click on the desktop = > open in terminal , i don't see the message of the day.

how can i fix that?


Hi Asaf,

/etc/motd is only displayed in login shells. To make it display in non-login shells, you can, for example, create a short script in /etc/profile.d/. Let's say motd.sh. Put something like the following in it (the test is just to make sure a terminal is actually attached, and /etc/motd is readable):

[ -n "$TERM" -a -r /etc/motd ] && cat /etc/motd

i thought about it but if i do this i get twice the motd when logged via putty :(

That is correct (the double display) since motd is a "default" of ssh.

You could add some logic to determine if the process is "gnome-terminal" and only display in that case, or determine if it is a remote connection, etc...
I'm trying to research which bash built-in would be of the most relevance in this case.

Else, you could do something like, add the following to your .bashrc

set | grep ^GNOME > /dev/null  && cat /etc/motd

The problem with that, however, is whether there is always a "GNOME_" environment variable set. I would assume this would work in most cases though.

Also - I have started to abandon modifying /etc/profile and instead have started to look at /etc/profile.d/

I'm thinking you could use shopt to test for a non-login shell. Like this:

if ! $(shopt -q login_shell); then [ -n "$TERM" -a -r /etc/motd ] && cat /etc/motd; fi

It's getting a wee bit complicated, but it should work.

Nice. ;-)

I guess I was trying to find a "shell internal" (not a builtin) that would easily identify the login type (i.e. $$ or $_ , etc...) I still have not found anything absolute that works. But, I think either of the suggestions thus far should work in most scenarios.

Thanks that a good solution i think :)

and I now have a new favorite thing for the day.... ;-) I might even add cowsay to my .bashrc now.

# [ -f /usr/bin/cowsay ] && echo "Well lookee here" | cowsay -f tux
< Well lookee here >
       |o_o |
       |:_/ |
      //   \ \
     (|     | )
    /'\_   _/`\

cowsay is pretty amusing ;-)