From 6a24626f332e40357e13e82a9349fe6257f03dc5 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Fri, 29 Jun 2012 20:39:44 -0400 Subject: [PATCH] logs: improve ability to find logs --- log/summarize.pl | 4 ++-- log/watch.pl | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/log/summarize.pl b/log/summarize.pl index c4616ff..1201aa0 100755 --- a/log/summarize.pl +++ b/log/summarize.pl @@ -284,8 +284,8 @@ sub get_qp_dir { return "$homedir"; }; foreach my $s ( qw/ smtpd qpsmtpd qpsmtpd-dev / ) { - if ( -d "$homedir/smtpd/plugins" ) { - return "$homedir/smtpd"; + if ( -d "$homedir/$s/plugins" ) { + return "$homedir/$s"; }; }; }; diff --git a/log/watch.pl b/log/watch.pl index b93ff6e..0514a3d 100755 --- a/log/watch.pl +++ b/log/watch.pl @@ -3,11 +3,12 @@ use strict; use warnings; +use Cwd; use Data::Dumper; use File::Tail; -my $dir = find_qp_log_dir() or die "unable to find QP home dir"; -my $file = "$dir/main/current"; +my $dir = get_qp_dir() or die "unable to find QP home dir"; +my $file = "$dir/log/main/current"; my $fh = File::Tail->new(name=>$file, interval=>1, maxinterval=>1, debug =>1, tail =>100 ); while ( defined (my $line = $fh->read) ) { @@ -15,16 +16,21 @@ while ( defined (my $line = $fh->read) ) { print $line; }; -sub find_qp_log_dir { +sub get_qp_dir { foreach my $user ( qw/ qpsmtpd smtpd / ) { - my ($homedir) = (getpwnam( $user ))[7] or next; - if ( -d "$homedir/log" ) { - return "$homedir/log"; + if ( -d "$homedir/plugins" ) { + return "$homedir"; }; - if ( -d "$homedir/smtpd/log" ) { - return "$homedir/smtpd/log"; + foreach my $s ( qw/ smtpd qpsmtpd qpsmtpd-dev / ) { + if ( -d "$homedir/$s/plugins" ) { + return "$homedir/$s"; + }; }; }; + if ( -d "./plugins" ) { + return Cwd::getcwd(); + }; }; +