GNU/Linux Desktop Survival Guide by Graham Williams |
|||||
Tricks with /etc/issue
Category: Software
All the software discussed in this small article can be downloaded here. This includes shell scripts called createissue and listansi.
When you log in on the console of your Linux System, you are usually presented with a login screen with info about the system you are about to log in on. In this short article I will show you how to change what you see on your login screen, and also how to add a bit of colour.
When your Linux System boots it starts "getty" processes on a number of virtual terminals on your system. When getty starts, it prints the contents of /etc/issue to the terminal. To customize the look of your console, all you have to do is edit /etc/issue.
You can also add colour by using the colour capabilities of the Linux console. The Linux console, like almost any other existing terminal, has escape sequences that can be used to change the appearance of text on screen. Piping the following script into /etc/issue:
#!/bin/sh spaces(){ COUNT=0; while [ $COUNT -lt $1 ]; do echo -ne " "; COUNT=$[$COUNT+1] done } esc="\033[" echo -ne "${esc}H${esc}J\n${esc}44;37;1m" WELCOME="Welcome to "`hostname`" running Linux "`uname -r` CHARS=$[(80-`echo $WELCOME | wc --chars`)/2] spaces $CHARS echo -ne $WELCOME spaces $CHARS echo -ne "${esc}0m\n\\l " |
should produce this result:
Welcome to gatekeeper.localnet running Linux 2.2.16
tty1 gatekeeper login:
Note to newbies: Piping the output of a program into a file involves using the > operator. For example, to send the output of "ls" to a file called "files.txt", you would do this: ls > files.txt
The line responsible for all the color is this one:
echo -ne "${esc}H${esc}J\n${esc}44;37;1m" |
The 44;37 specifies White on Blue. To see how your terminal renders colours, use this script:
#!/bin/bash # Display ANSI colours. # esc="\033[" echo -n " _ _ _ _ _40 _ _ _ 41_ _ _ _42 _ _ _ 43" echo "_ _ _ 44_ _ _ _45 _ _ _ 46_ _ _ _47 _" for fore in 30 31 32 33 34 35 36 37; do line1="$fore " line2=" " for back in 40 41 42 43 44 45 46 47; do line1="${line1}${esc}${back};${fore}m Normal ${esc}0m" line2="${line2}${esc}${back};${fore};1m Bold ${esc}0m" done echo -e "$line1\n$line2" done |
You can download both scripts here.
Please note that Redhat Linux overwrites /etc/issue with each bootup. To keep your /etc/issue, edit /etc/rc.d/rc.local and remove the lines responsible for overwriting /etc/issue. Even better, change rc.local to use createissue instead.
Any comments will be appreciated. You can email me at gpf@linuxuser.co.za