4

I would like to have Ubuntu's MOTD in the fish shell.

Ubuntu's default is as follows:

Default Ubuntu MOTD

That is essentially what I would like to see when open up my terminal (terminator, which loads fishfish) As far as I can make out (Based on the information here), the default shell executes pam_motd, which in turn executes a bunch of scripts from /etc/update-motd.d

I don't know how to do this in the fish shell with any confidence. I haven't been able to find any information by searching.

Cheers

1
  • 1
    You don't normally get the motd when you start a terminal emulator. You only see it when you log in in text mode. This answer might help. What are you trying to do? If you want to see the motd, run cat /etc/motd. On Ubuntu, that file is generated dynamically, but that has nothing to do with your shell. Sep 1, 2012 at 2:11

5 Answers 5

4

Put this in your ~/.config/fish/config.fish:

function fish_greeting
  status --is-login
  if [ $status != 0 ] 
    cat /run/motd.dynamic
  end 
end

This will make sure that you don't get the double motd when logging in remotely.

2
+50

all the executions you mention happen at boot, they produce the file /etc/motd simply cat /etc/motd in your config file, ie. add

cat /etc/motd

to the file ~/.config/fish/config.fish

/B2S

4
  • Thanks! Unfortunately that only produces the welcome note and documentation link. It doesn't execute those scripts that are executed by the bash shell
    – eggonlegs
    Aug 30, 2012 at 1:24
  • 1
    indeed, those are not executed by the bash shell, but by the boot procedure. In some cases they will also be the package manager or similar to let you know that there are updates, etc. to run them manually run: run-parts --lsbsysinit /etc/update-motd.d > /run/motd
    – Born2Smile
    Aug 30, 2012 at 2:02
  • When I ssh in remotely, I get that update text and so forth (in bash). I guess I am confused about login shells and whatnot.
    – eggonlegs
    Sep 1, 2012 at 10:26
  • 1
    The story goes: When the machine boots, all the scripts in /etc/update-motd.d are run to produce /etc/motd, thenafter whenever you start a login shell, through say ssh, the login shell (in this case bash) will display the contents of /etc/motd. So bash does not execute any scripts itself, it just displays the contents of /etc/motd when you log in. You can have any shell do that, if the shell won't do it by default, just add cat /etc/motd to the *rc-file of that shell. See my answer above for how to do that in fish shell. If what you really want is to change shell to fish, simply chsh
    – Born2Smile
    Sep 2, 2012 at 11:07
2

From the fish shell documentation:

If a function named fish_greeting exists after initialization, it will be run when entering interactive mode. Otherwise,if an environment variable named fish_greeting exists, it will be printed.

When you set fish_greeting, this overrides the default help text.

In a properly set-up Ubuntu system, the message of the day is created with a series of scripts in /etc/update-motd.d and cached in /run/motd. So you can add to ~/.config/fish/config.fish:

function fish_greeting
    cat /run/motd
end
1

For Ubuntu 18.04 and later with the /usr/sbin/update-motd command available, put the following in .config/fish/functions/fish_greeting.fish:

function fish_greeting
  set stamp "$HOME/.motd_shown"
  # Only display this information in interactive/not login shells
  if not status is-login; and status is-interactive
    # Also, don't display if .hushlogin exists or MOTD was shown recently
    if [ ! -e "$HOME/.hushlogin" ]; and [ -z "$MOTD_SHOWN" ]; and not find $stamp -newermt 'today 0:00' 2> /dev/null | grep -q -m 1 '.'
      [ (id -u) -eq 0 ]; or set SHOW "--show-only"
      update-motd $SHOW
      touch $stamp
      export MOTD_SHOWN=update-motd
    end
  end
  set -e stamp
end

The above script for the fish shell is based on /etc/profile.d/update-motd.sh included in the package show-motd. It respects the .hushlogin file in your home directory and only shows the MOTD once a day. It's my first fish shell script, so there could be some mistakes - but it seems to work fine for me so far.

0

Debian-based such as Ubuntu has /etc/issue , This can a set of escape code such as \n \l , When you try to login from another tty you'll see /etc/issue's content.Of course it's when possible you don't use MOTD system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.