Ordinarily, when bash (or any other shell) starts up on a linux machine, all the user gets is a single prompt. If the user wants information about the status of his account, like how many mail messages he has, the user has to specifically ask for that information. Instead, you might want to set it up so that when a user logs in, he sees a message across the top of the screen, displaying that sort of information. Using a dynamically generated banner instead of just a static motd has the advantage that it can display this sort of information. Two examples, both based on the same set of core scripts, are shown below.

Pretty login banner on binxThe pretty login banner on quentin

The login banners display useful information, both about the user (about of mail) and about the system (system load). The banners also contain a warning about logging, instructions for getting help, the time, the date, and the word of the day. The banner systems shown above are both written in C and shell scripting – for simplicity, I will not go into implementation details, but will rather show the general ideas necessary to get started.

Probably the most prominent part of the login banner is the name of the computer: ‘binx iv’ on the first and ‘quentin’ on the second. Each is written in letters generated with figlet and stored in a special file /usr/local/lib/hello/banner, along with the border and other static text.

.----------------------------------------------------------------------------.
|                                                                            |
|                             __  _                                          |
|         ___  __ _____ ___  / /_(_)__   robotics                            |
|        / _ `/ // / -_) _ \/ __/ / _ \  backroom                            |
|        \_, /\_,_/\__/_//_/\__/_/_//_/  server                              |
|         /_/ quentin.mbhs.edu                                               |
|                                                                            |
|                                                                            |
|                                                                            |
|                                                                            |
|                                                                            |
|----------------------------------------------------------------------------|
|         Please be aware that all activity on Quentin is logged.            |
|                If you do not like this, disconnect now.                    |

The program that displays the entire banner prints this file out and then moves the cursor around with the curses library, filling in the rest of the information. How this information is gotten is trivial, since nearly all of it can be fetched with one-line shell commands. Don’t waste time looking for a word of the day program, just write your own (10 lines in perl or less), and download a word list from the Internet (they abound).

If you are experienced with ASCII art, you may want to create the system name ‘picture’ by hand; otherwise, you will want to use the handy figlet program. If you type figlet text, figlet creates a large ‘text’.

root@quentin:/usr/local/lib/hello# figlet quentin
                        _   _
  __ _ _   _  ___ _ __ | |_(_)_ __
 / _` | | | |/ _ \ '_ \| __| | '_ \
| (_| | |_| |  __/ | | | |_| | | | |
 \__, |\__,_|\___|_| |_|\__|_|_| |_|
    |_|

This size probably does not suit you. The first image above used the ’small’ figlet font: figlet -f small binx iv. The second image used the small slanted figlet font: figlet -f smslant quentin. Other fonts are available in the man pages. Now that you have generated the text, you can copy it into your banner file. You may also want to include your domain name, a very short description of the function of your server, and a notice about logging.

Assuming you know or learned enough about the curses library to finish creating your script, you are now ready to install it. On our systems, the program to display the banner is called ‘hello’. Installing it is simple – ensure it is in a world-readable directory, and then add a call to it at the end of /etc/profile.

Related posts: