#!/bin/bash # # /usr/local/sbin/showlog # Copyright 2002 Jonas Smedegaard # # $Id: showlog,v 1.5 2002-03-14 14:40:57 jonas Exp $ # # Show topic-specific log entries # # halt on errors (NB! this is a bashism...) set -e function usage() { echo "Usage: $(basename $0) ftp|web|weberror|websuexec|mail|system [ [...]]" exit 1 } function exit1() { echo "Error: $1" echo "Exiting..." exit 1 } tail_history="50" target=$1 logroot="/var/log" case "$target" in ftp) log="xferlog" logs="$log.??.gz $log.?.gz $log.? $log" ;; web) logroot="/var/log/apache" log="access.log" logs="$log.??.gz $log.?.gz $log.? $log" ;; weberror|weberrors) logroot="/var/log/apache" log="error.log" logs="$log.??.gz $log.?.gz $log.? $log" ;; websuexec) logroot="/var/log/apache" log="suexec.log" logs="$log.??.gz $log.?.gz $log.? $log" ;; mail) log="mail.log" logs="$log.??.gz $log.?.gz $log.? $log" ;; system) log="syslog" logs="$log.??.gz $log.?.gz $log.? $log" ;; *) usage ;; esac shift function cat_logs() { logroot=$1 shift for pattern in $@; do for file in `find $logroot -name "$pattern" -type f -mindepth 1 -maxdepth 1 -follow | sort`; do case $pattern in *.gz) zcat $file;; *.bz2) bzcat $file;; *) cat $file;; esac done done } if [ $# \> 0 ]; then grep_opts="" for keyword in $@; do grep_opts="$opts -e $keyword" done cat_logs $logroot $logs | grep -i $grep_opts | tail -n $tail_history [ -f $logroot/$log ] && tail -n 0 -f $logroot/$log | grep -i $grep_opts else cat_logs $logroot $logs | tail -n $tail_history [ -f $logroot/$log ] && tail -n 0 -f $logroot/$log fi