Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I would like to colorize my ssh banner. I know I can perform it like so:

In /etc/profile I can put:

echo -e "\e[1;31m Colorful text"
echo -e "\e[0m Reset"

But I have some ASCII art in the banner with special characters. Is there any way to colorize this without escaping every single special char in the ASCII art?

share|improve this question
    
Every character is special in its own way. –  Ignacio Vazquez-Abrams May 17 '13 at 12:02
add comment

2 Answers 2

Generic Colouriser

Generic Colouriser could be used for this application. It has the capability to identify via regular expressions bits of text, and then assign a color to any that match.

# this is probably a pathname
regexp=/[\w/\.]+
colour=green
count=more

This will match /usr/bin, /usr/local/bin/, /etc/init.d/syslogd and similar strings and paint it with green.

Another example:

regexp=^-{1,2}\s{0,1}$
colours=red
count=block
-
regexp=^\s{0,5}$
colours=default
count=unblock

This will turn all correctly formatted mail signatures red.

Screenshot

        ss of syslog

MOTD Maker

Came across this GUI, MOTD Maker which allows you to interactively create your MOTD and save it as a text file. App is a windows application but ran find under Wine.

    ss of motd maker #1

    ss of motd maker #2

Linux Logo

This one, linux_logo, has been around since I started using Linux daily in 1997, so it's an oldie but it still looks good and has a surprising array of features.

This one is more a logo with system related stats being displayed, but you can incorporate your own text so it's related to your question.

    linux_logo #1

    linux_logo #2

ScriptEchoColor

ScriptEchoColor simplifies Linux terminal text colorizing, formatting and several steps of script coding.

For Example

1. Wait for a key press:
    echoc -w
    echoc -w "When you ready"

2. Ask a question and receive an \"yes/no\" answear:
    if echoc -q "Ready to continue"; then
        echo "Hello"
    fi

      ss ScriptEchoColor

References

share|improve this answer
add comment

You might want to have a look at toilet. The following has been incorporated in the banner of one of the servers at my lab:

enter image description here

You can install it on Debian based systems with

sudo apt-get install toilet

TOIlet prints text using large characters made of smaller characters. It is similar in many ways to FIGlet with additional features such as Unicode handling, colour fonts, filters and various export formats.

toilet works perfectly well with ASCII art:

enter image description here


I have written a little Perl script to highlight specific regexes in text. If you use . as the regex, it will color everything a specific color:

enter image description here

The script (use -h for a tiny help message):

#!/usr/bin/env perl
use Getopt::Std;
use strict;
use Term::ANSIColor; 

my %opts;
getopts('hic:l:',\%opts);
    if ($opts{h}){
    print "Use -l to specify the letter(s) to highlight. To specify more than one patern use commas.\n -i makes the search case sensitive\n -c: comma separated list of colors\n";
    exit;
    }
my $case_sensitive=$opts{i}||undef;
my @color=("bold blue",'bold red', 'bold yellow', 'bold green', 'bold magenta', 'bold cyan', 'yellow on_magenta', 'bright_white on_red', 'bright_yellow on_red', 'white on_black');
if ($opts{c}) {
   @color=split(/,/,$opts{c});
}
my @patterns;
if($opts{l}){
     @patterns=split(/,/,$opts{l});
}
else{
    $patterns[0]='\*';
}
# Setting $| to non-zero forces a flush right away and after 
# every write or print on the currently selected output channel. 
$|=1;

while (my $line=<>) 
{ 
    for (my $c=0; $c<=$#patterns; $c++){
      if($case_sensitive){
        if($line=~/$patterns[$c]/){
        $line=~s/($patterns[$c])/color("$color[$c]").$1.color("reset")/ge; 
        }
      }
      else{
        if($line=~/$patterns[$c]/i){
          $line=~s/($patterns[$c])/color("$color[$c]").$1.color("reset")/ige; 
        }
      }
    }
    print STDOUT $line;
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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