From 121a207e681946a67bdc9914538503653c8df07c Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Fri, 22 Feb 2002 19:43:46 +0000 Subject: showlog: New command to list logfiles with simple options (targeted at local admins). --- showlog | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 showlog (limited to 'showlog') diff --git a/showlog b/showlog new file mode 100755 index 0000000..a6d57a0 --- /dev/null +++ b/showlog @@ -0,0 +1,85 @@ +#!/bin/bash +# /usr/local/sbin/showlog: Show topic-specific log entries +# Written by Jonas Smedegaard + +# halt on errors (NB! this is a bashism...) +set -e + +function usage() { + echo "Usage: $(basename $0) ftp|web|weberror|mail [ [...]]" + exit 1 +} + +function exit1() { + echo "Error: $1" + echo "Exiting..." + exit 1 +} + +target=$1 + +case "$target" in + ftp|web|weberror|mail) + ;; + *) + usage + ;; +esac + +shift + +logroot="/var/log" +tail_history="100" + +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 +} + +LOCALCONFIG=/etc/local/showlog.conf +. $LOCALCONFIG || exit1 "Unable to read local config file $LOCALCONFIG" + +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) + logroot="/var/log/apache" + log="error.log" + logs="$log.??.gz $log.?.gz $log.? $log" + ;; + mail) + log="mail.log" + logs="$log.??.gz $log.?.gz $log.? $log" + ;; +esac + +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 -- cgit v1.2.3