Tomcat on Linux


#!/usr/bin/perl
#########################
#
# This is a prototype tomcat log transfer file
# Since the access valve file is not write locked and can be deleted
# we need to re-initate loggin after copying the file. This can be
# done by restarting tomcat...there might be other ways.
#
########################

use strict;
use warnings;

my $log = "/root/cronscripts/log_send.log";

open LOG, ">>$log";
print LOG "\n\nStarting log transfer at " . `date`;

    # the logs look like the following
    # /var/log/tomcat/base/access_log.2004-10-28

my $dir = "/var/log/tomcat/base/";
opendir DIR, $dir;

my @dir = ();
while (my $name = readdir DIR) {

    next unless ($name =~ /^acc/);   # next unless the entry starts with 'acc'

        # note: I don't think tomcat access logs are compressed by the log deamon
        #       (unlike apache) so I am skipping this next line
        # next unless ($name =~ /\.gz$/);  # next unless the entry ends with '.gz'

    push @dir, $name;
}

my $message;
foreach (sort @dir) {

        print LOG "Sending file $_\n";
        $message = `scp ${dir}${_} stats\@stats.cats.ohiou.edu:data/logs/iliad2/`;

        if ($message) {
            print LOG "\n--error copying file---\n";
            print LOG "message: $message\n";
            exit;
        }
        print LOG "file sent\n";
        print LOG "Deleting log ${dir}${_}\n";
        $message = `rm $dir$_`;

        if ($message) {
            print LOG "\n--error deleting file---\n";
            print LOG "message: $message\n";
            exit;
        }

}

# Now restart tomcat to get a new log file
$message = `/etc/init.d/tomcat restart`;
print LOG $message;



1 ToDo
1.1 Add restart=success test
On the last line, $message recieves the results of the start command. It has happened that the start failed and $message is empty. (I suspect because the tomcat init failure goes to std_err).



Comments