With a little side of applesauce...

Thursday, February 1, 2007

Using gnome-terminal to simplify web farm maintenance

Gnome-terminal has a wonderful interface for those of us that run many server machines. I run server farms, so was looking for a way to simplify debugging across multiple machines (by tailing the logs on each machine). The following PERL script will open a new gnome-terminal window plus an additional three tabs, all of which are tailing a specified access or error log. This script is Debian-centric, and written to take advantage of gnome-terminal features, but should easily be modified to your favourite distribution


# sample usage: tail.pl www.example.com access
# test to see if there are 2 parameter, or if # the first parameter is --help. Also, check to
# see if the 2nd parameter equals "access", or # "error". If not, print the usage line.
if (($#ARGV != 1) || ($ARGV[1] eq "--help") || ( $ARGV[1] !~ m/(access|error)/ ))
print "Usage: ".$0." [fqdn] [access|error] \n";

## set the variables
# array of hosts to which we want to connect
@HOSTS=('www1.private.com', 'www2.private.com', 'www3.private.com', 'www4.private.com');

# set $VHOST to the fqdn
$VHOST = $ARGV[0];

# change the periods in the fqdn to underscores
$VHOST =~ s/\./\_/g;

# set $LOG to either "error" or "access"

## foreach name in @HOSTS add a new tab to the terminal window and execute the following command:
# ssh -t host --tab -e "ssh -t web2priv4 'tail -f /var/log/apache2/web3_unt_edu_error_log'"
#### This is where you would want to modify this script to make it work with your
#### favorite terminal. foreach $host (@HOSTS)
$FLAGS=$FLAGS." --tab -e \"ssh -t ".$host." 'tail -f /var/log/apache2/".$VHOST."_".$LOG."_log' \" " ;

$command = "/usr/bin/gnome-terminal ".$FLAGS;
print "$command";

No comments: