23

I'm getting more familiar with tweaking the way things look in a shell via the prompt (.bashrc), but I'm now trying to change the initial stuff displayed when I first log in. On my EC2 instance, this is what I see when I log in:

         __|  __|_  )  Fedora 8
         _|  (     /    32-bit
        ___|\___|___|


  Welcome to: 

    Wowza Media Server 2 for Amazon EC2

      Version: 2.0.0.08

On my home Mint computer, here's what I see when I log in:

Welcome to Linux Mint 11 Katya (GNU/Linux 2.6.38-8-generic x86_64)

Welcome to Linux Mint
* Documentation:  http://www.linuxmint.com

Last login: Tue Jun 21 17:44:05 2011

Where is this defined? How can I tweak it for some mad ASCII art ACTION?

31

The text displayed before the login prompt is stored in /etc/issue (there's a related file, /etc/motd, that's displayed after the user logs in, before their shell is started). It's just a normal text file, but it accepts a bunch of escape sequences:

  • \b -- Baudrate of the current line.
  • \d -- Current date.
  • \s -- System name, the name of the operating system.
  • \l -- Name of the current tty line.
  • \m -- Architecture identifier of the machine, eg. i486
  • \n -- Nodename of the machine, also known as the hostname.
  • \o -- Domainname of the machine.
  • \r -- Release number of the OS, eg. 1.1.9.
  • \t -- Current time.
  • \u -- Number of current users logged in.
  • \U -- The string "1 user" or " users" where is the number of current users logged in.
  • \v -- Version of the OS, eg. the build-date etc.

On my machine I have:

This is \n (\s \m \r) \t \l

Which is rendered as:

This is etudes-1 (Linux x86_64 2.6.39-gentoo) 17:43:10 tty1

6

The file /etc/issue and /etc/issue.net are the files displayed by the login program. You can put special expansion characters in it, as noted on the other answer. But you may also want to try the linux_logo program. It can generate really nice ASCII art issue files for you.

4

the user clearly is asking about messages displayed AFTER log in, all "/etc/issue" are displayed BEFORE login+password is entered so are off-topic.

The 'login shell' steps are:

  1. show messages contained in "/etc/issue"
  2. ask for user and pass
  3. show Message Of The Day from:

    /etc/motd

    /etc/update-motd.d

  4. start /etc/profile and ~/.bash_profile

NB .bashrc is executed for NON login shell

@Naftuli Kay add your ASCII art to /etc/motd or add script in /etc/update-motd.d or /etc/profile for user independent prints, or ~/.bash_profile for single user prints

3

From Ask Ubuntu:

Ubuntu splash screen.png

Check the Ask Ubuntu link above for comments and possibly new answers from other users.

now bash script

The heavy lifting is the splash component that shows this:

$ now

Weather report: Edmonton               March 2018            ┌────────────────────────────┐
                                  Su Mo Tu We Th Fr Sa       │   ┏━┓╺┓  ┏━┓┏━┓   ┏━┓┏┳┓   │
     \   /     Sunny                           1  2  3       │   ┃┃┃ ┃ ╹┏━┛┗━┫   ┣━┛┃┃┃   │
      .-.      -23--14 °C          4  5  6  7  8  9 10       │   ┗━┛╺┻╸╹┗━╸┗━┛   ╹  ╹ ╹   │
   ― (   ) ―   ↘ 22 km/h          11 12 13 14 15 16 17       └────────────────────────────┘
      `-’      14 km              18 19 20 21 22 23 24  
     /   \     0.9 mm             25 26 27 28 29 30 31  

Yes it really is -14 in Edmonton and feels like -23. A good time to spend the long-weekend inside playing the newly arrived Tomb Raider 2013! Maybe brush up on that Resume to move to Vancouver or Montreal...

Here is the code:

#!/bin/bash

# NAME: now
# PATH: $HOME/bin
# DESC: Display current weather, calendar and time
# CALL: Called from terminal or ~/.bashrc
# DATE: Apr 6, 2017. Modified: Mar 30, 2018.

# NOTE: To display all available toilet fonts use this one-liner:
#       for i in ${TOILET_FONT_PATH:=/usr/share/figlet}/*.{t,f}lf; do j=${i##*/}; toilet -d "${i%/*}" -f "$j" "${j%.*}"; done

# Setup for 92 character wide terminal
DateColumn=34 # Default is 27 for 80 character line, 34 for 92 character line
TimeColumn=61 # Default is 49 for   "   "   "   "    61 "   "   "   "

#--------- WEATHER ----------------------------------------------------------

# Current weather, already in color so no need to override
echo " "
# Replace Edmonton with your city name, GPS, etc. See: curl wttr.in/:help
curl wttr.in/Edmonton?0 --silent --max-time 3
# Timeout #. Increase for slow connection---^

echo " "
echo " "                # Pad with blank lines for calendar & time to fit

#--------- DATE -------------------------------------------------------------

# calendar current month with today highlighted.
# colors 00=bright white, 31=red, 32=green, 33=yellow, 34=blue, 35=purple,
#        36=cyan, 37=white

tput sc                 # Save cursor position.
# Move up 9 lines
while [ $((++i)) -lt 10 ]; do tput cuu1; done

# Depending on length of your city name and country name you will:
#   1. Comment out next three lines of code. Uncomment fourth code line.
#   2. Change subtraction value and set number of print spaces to match
#      subtraction value. Then place comment on fourth code line.

Column=$(($DateColumn - 10))
tput cuf $Column        # Move x column number
printf "          "     # Blank out ", country" with x spaces
#tput cuf $DateColumn    # Position to column 27 for date display


# -h needed to turn off formating: https://askubuntu.com/questions/1013954/bash-substring-stringoffsetlength-error/1013960#1013960
cal -h > /tmp/terminal

CalLineCnt=1
Today=$(date +"%d")
# Prefix with space when length < 2
if [[ ${#Today} < 2 ]] ; then
    Today=" "$Today
fi
printf "\033[32m"   # color green -- see list above.

while IFS= read -r Cal; do
    printf "$Cal"
    if [[ $CalLineCnt > 2 ]] ; then
        # See if today is on current line & invert background
        tput cub 22
        for (( j=0 ; j <= 18 ; j += 3 )) ; do
            Test=${Cal:$j:2}            # Current day on calendar line
            if [[ "$Test" == "$Today" ]] ; then
                printf "\033[7m"        # Reverse: [ 7 m
                printf "$Today"
                printf "\033[0m"        # Normal: [ 0 m
                printf "\033[32m"       # color green -- see list above.
                tput cuf 1
            else
                tput cuf 3
            fi
        done
    fi

    tput cud1               # Down one line
    tput cuf $DateColumn    # Move 27 columns right
    CalLineCnt=$((++CalLineCnt))
done < /tmp/terminal

printf "\033[00m"           # color -- bright white (default)
echo ""

tput rc                     # Restore saved cursor position.

#-------- TIME --------------------------------------------------------------

tput sc                 # Save cursor position.
# Move up 9 lines
i=0
while [ $((++i)) -lt 10 ]; do tput cuu1; done
tput cuf $TimeColumn    # Move 49 columns right

# Do we have the toilet package?
if hash toilet 2>/dev/null; then
    echo " "$(date +"%I:%M %P")" " | \
        toilet -f future --filter border > /tmp/terminal
# Do we have the figlet package?
elif hash figlet 2>/dev/null; then
    echo $(date +"%I:%M %P") | figlet > /tmp/terminal
# else use standard font
else
    echo $(date +"%I:%M %P") > /tmp/terminal
fi

while IFS= read -r Time; do
    printf "\033[01;36m"    # color cyan
    printf "$Time"
    tput cud1               # Up one line
    tput cuf $TimeColumn    # Move 49 columns right
done < /tmp/terminal

tput rc                     # Restore saved cursor position.

exit 0

Prerequisites

For the fancy time display you need to install toilet:

sudo apt install toilet

For another fancy time display (but not quite as fancy) install figlet:

sudo apt install figlet

Otherwise the time will be displayed in "normal" font.

Weather

Weather is provided by the curl wttr.in/cityname?0 command. In your terminal use: curl wttr.in/:help for additional details.

Weather: Change city name

You'll want to modify this section of code and change Edmonton to your city name:

# Replace Edmonton with your city name, GPS, etc. See: curl wttr.in/:help
curl wttr.in/Edmonton?0 --silent --max-time 3
# Timeout #. Increase for slow connection---^

Unicode is supported for city names like /Москва (Moscow). Airport letters are supported such as YEG for Edmonton.

Weather: Remove country name

When terminal is set for 92 characters wide, the weather displays as "Edmonton, Canada." which is too long for my liking:

Weather with country.png

Worse yet when terminal is set for default 80 characters wide:

Weather country name 80 chars.png

To circumvent the problem, ", Countryname" is blanked out on the screen with this code:

# Depending on length of your city name and country name you will:
#   1. Comment out next three lines of code. Uncomment fourth code line.
#   2. Change subtraction value and set number of print spaces to match
#      subtraction value. Then place comment on fourth code line.
Column=$(($DateColumn - 10))
tput cuf $Column        # Move x column number
printf "          "     # Blank out ", country" with x spaces
#tput cuf $DateColumn    # Position to column 27 for date display

If you need help with this part of the script please post comment below for assistance.

Terminal screen width adjustments

Adjust the spacing to your terminal screen width by changing:

# Setup for 92 character wide terminal
DateColumn=34 # Default is 27 for 80 character line, 34 for 92 character line
TimeColumn=61 # Default is 49 for   "   "   "   "    61 "   "   "   "

Tying it all together in ~/.bashrc

Edit your ~/.bashrc file and add these lines to the bottom:

# Splash Calendar and time
now

# ASCII Linux distribution display
screenfetch

Save the `~/.bashrc" file changes.

To display the Ubuntu information you need screenfetch:

sudo apt install screenfetch

There are similar display packages to screenfetch so shop around!

If you want the same command prompt with "─────────" dividing line between commands, change these lines:

if [ "$color_prompt" = yes ]; then
    PS1='───────────────────────────────────────────────────────────────────────────────────────────
${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='───────────────────────────────────────────────────────────────────────────────────────────
${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

Note the length of the separator line coincides with width of screenfetch output. In this case it is 92 characters wide and gnome-terminal preferences are set accordingly.

1

You can also configure the ssh daemon to display a message during login. Specify the file to display with the Banner directive in the sshd_config file:

Banner /etc/ssh/ssh_banner

The filename can be any file, but for sanity I keep it in /etc/ssh along with the sshd_config file.

0

One little script to generate the /etc/issue with network address in /etc/rc.local of debian host.

/bin/echo "This is \n(\s \m \r) \t \l">/etc/issue
/bin/sleep 10 # This is optional, sometimes OS need more time to get ip address while DHCP, otherwise maybe you will get nothing :(
/sbin/ip a| /bin/grep inet| /bin/grep -v -E "inet6|127.0.0.1"| /bin/sed "s/\s*//"|/bin/sed "s/\/24.*//" >>/etc/issue

update: sounds it's enough with "ip -4 -br a" thanks @Mathieu CAROFF !

  • man ip. Use the -br switch. You might also want to use the -4 switch. Your command can be shortened to ip -br a | sed -nE 's:^(\w+)\s+UP\s+([0-9.]+)/.*$:\1 \2:p'. Even better, use hostname -I. – Mathieu CAROFF Jul 6 '18 at 9:16
0

IMPORTANT for use this ssh Banner: Day Highlighting only works with "ncal -bh > /tmp/terminal" instead of cal -h. cal -h doesnt work/exist anymore (Ubuntu 18.04)

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.