Displaying the host name of a UNIX server on login
September 27th, 2007 2 Comments
To show the host name of a server when you log in to it. Add the following at the end of your shell startup file (e.g. .bashrc or .cshrc in your home directory):
perl banner.pl
Then create the following Perl script in your home directory and call it banner.pl.
# Perl script for printing banner showing name of local host use Text::Banner;
$a = Text::Banner->new;
$a->set(`hostname`);
$a->size(1);
$a->fill('');
$a->rotate('h'); print "\n";
drawlines();
print $a->get;
drawlines();
print "\n";
print "\n"; sub drawlines() {
for ($loop=1; $loop<4; $loop++) {
for ($n=1; $n<60; $n++) {
print "=";
}
print "\n";
}
}
Finally, install the Text::Banner perl module from CPAN. Note: if you don't want to (or can't) install the Perl module in the normal way on the server, you can download the zip file from the CPAN Web site (http://search.cpan.org/~lory/Text-Banner-1.00/Banner.pm), gunzip and tar xvf it in your home directory and then change the 'use' statement to:use Banner::Banner;
Now, when you log in to the server you get something like this (in this case the server is called pegasus):
Potentially similar posts
- Scan for available IP addresses – August 2011
- Rails Chronicles – Part 2 – July 2011
- My first (useful) Ruby program – June 2011
- Perl basics for beginners (on Windows) – August 2010
- Gotchas with running a Perl script as a cron job – August 2010
April 18th, 2009 at 8:56 am (#)
If you do not want to have it generated everytime, you can use a program called figlet (http://www.figlet.org) on the linux/unix system. It does not usually come installed as standard.
You can install it in ubuntu (for example) by apt-get install figlet
The result is that you can generate text using different fonts. Once this has been generated, you can add it into the banner for the ssh/telnet/ftp server.
-Cary
April 19th, 2009 at 9:29 pm (#)
Thanks for the tip Cary.
I hadn't heard of figlet before.