#!/usr/bin/perl
#
# short_hostname Print out just the "base" of the hostname
#
# (`uname -n` can give either partial or full-name)
#
$hn = `hostname`;
#
# Ends in a "." ? Then remove it.
#
if( $hn =~ /(.*)\.$/ )
{
$hn = $1;
}
#
# Split into:
# ptolemy. .com
# metawire
#
if( $hn =~ /\./ )
{
$hn =~ /(.*)\.(.*)\.([a-zA-Z]*)$/;
print "$1\n";
}
else
{
print "$hn";
}
|