1

I installed mailutils on my linux machine with Linux Mint 15 (basically Ubuntu 13.04).

When I log in, I get the following:

Welcome to Linux Mint 15 Olivia (GNU/Linux 3.8.0-32-generic i686)

Welcome to Linux Mint
 * Documentation:  http://www.linuxmint.com
No mail.
Last login: Wed Nov  6 01:33:10 2013 from xxxxxxxxxxxxxxxxxxxxxxx
BFL SingleSC: 3s ago - [2013-11-06 01:37:33] 5s:57.83 avg:57.96 u:56.96 Gh/s

I have added the last line, colorized as I prefer, as a custom script that updates me on the status of my BFL bitcoin hashing rig in ~/.bashrc.

I now want to color the rest of it, especially the No mail. line, from mailutils, and remove the duplicated 'Welcome to Linux Mint' messages and newline.

I've been searching for the mailutils section specifically, and can't find any reference to it in:

  • ~/.bashrc
  • ~/.profile
  • /etc/profile
  • /etc/profile.d/*
  • /etc/bashrc
  • /etc/init.d/*
  • /etc/rc.local
  • /etc/rc*.d (1, 2, 3, 4, 5, 6, S)

So - how do I go about finding where these messages are generated so I can modify and color them as I like?

2
  • That message is coming from pam.
    – bahamat
    Nov 6, 2013 at 9:10
  • How do I colorize it?
    – Ehryk
    Nov 7, 2013 at 4:42

1 Answer 1

4

Updated answer based on some researching

Remove duplicated welcome messages

  • Since you login with ssh, the first welcome message should be coming from /etc/issue.net. To remove the message, just remove the contents of that file.
  • To remove the second welcome message, remove the contents of /etc/motd.

Colorize the line about mail

To colorize that line, the easiest option I can think of requires quite a bit of low-level work: the option is that you modify and build pam_mail.so yourself.

These are the steps for modifying it and installing the modified version

  1. Download Linux-PAM source from linux-pam.org (the official project site).
  2. Extract the source (this will create a new directory named Linux-PAM-1.1.8) and cd to it:

    # tar xzvf Linux-PAM-1.1.8.tar.gz
    # cd Linux-PAM-1.1.8
    
  3. Change the following lines (the lines which begins with +, 4 lines at all) in file modules/pam_mail/pam_mail.c to be as the following diff shows (produced with diff -u)(the filename pam_mail.c.new is just my temporary file that I could produce that diff):

    --- pam_mail.c  2013-06-18 17:11:21.000000000 +0300
    +++ pam_mail.c.new      2013-12-29 16:57:49.759298926 +0200
    @@ -294,17 +294,17 @@
              switch (type)
                {
                case HAVE_NO_MAIL:
    -             retval = pam_info (pamh, "%s", _("No mail."));
    +             retval = pam_info (pamh, "%s", _("\\033[0;1;31mNo mail.\\033[0m"));
                  break;
                case HAVE_NEW_MAIL:
    -             retval = pam_info (pamh, "%s", _("You have new mail."));
    +             retval = pam_info (pamh, "%s", _("\\033[0;1;31mYou have new mail.\\033[0m"));
                  break;
                case HAVE_OLD_MAIL:
    -             retval = pam_info (pamh, "%s", _("You have old mail."));
    +             retval = pam_info (pamh, "%s", _("\\033[0;1;31mYou have old mail.\\033[0m"));
                  break;
                case HAVE_MAIL:
                default:
    -             retval = pam_info (pamh, "%s", _("You have mail."));
    +             retval = pam_info (pamh, "%s", _("\\033[0;1;31mYou have mail.\\033[0m"));
                  break;
                }
            else
    

    I have simply added \\033[0;1;31m to the beginning of those messages and \\033[0m to the end of those messages.

    Note: Now it displays those messages as red; from ascii-table.com page about Ansi Escape Sequences under title Set Graphics Mode you can find more complete list about colors and other tricks about customising terminal output.

  4. Compile it (Note: from here to the end I assume that your working directory is Linux-PAM-1.1.8, the very same directory to which we cd'd at the beginning, i.e. the "root" directory of the Linux-PAM package):

    # ./configure
    # make
    
  5. Backup your existing pam_mail.so in case that the new one breaks your system (I doubt it will break, but it's always good to have the original file in safe):

    # cp /lib/i386-linux-gnu/security/pam_mail.so ~/
    
  6. Copy the file modules/pam_mail/.libs/pam_mail.so to /lib/i386-linux-gnu/security/:

    # cp modules/pam_mail/.libs/pam_mail.so /lib/i386-linux-gnu/security/
    
  7. Log out and again in (or start a new ssh session, whatever), and you should see red "No mail." message (assuming you have no new mail).

The old, obsolete answer

The mail message can be disabled by changing the following line in file /etc/pam.d/system-login from

session optional pam_mail.so dir=/var/spool/mail standard

to

session optional pam_mail.so dir=/var/spool/mail nopen

Reference from archlinux's forums.

The text before the mail information is in /etc/motd, and you can disable it to be printed when login with ssh by putting the following line to ~/.ssh/config:

PrintMotd no
3
  • Hmm, I'm tracing down some of this. I don't have a system-login file, but I do have /etc/pam.d/login file that has a call to pam_mail.so, which I have traced to /lib/i386-linux-gnu/security. What I really want to do is just inject colors before and after the output, so that messages like No Mail are in a different color.
    – Ehryk
    Nov 7, 2013 at 2:40
  • I have tried echo -e "\e[36m" in /etc/pam.d/login, with no luck. I can color the entire thing by editing files in /etc/update-motd.d/ however this colors the mail prompt and the last login time, and I can't seem to isolate the mail part. I feel like I'm getting close - any ideas?
    – Ehryk
    Nov 7, 2013 at 2:42
  • I think too that you are getting close, but I don't have any ideas now. I'll take a deeper look at it when I have some time.
    – user37607
    Nov 7, 2013 at 7:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .