summaryrefslogtreecommitdiff
path: root/showlog
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2002-02-22 19:43:46 +0000
committerJonas Smedegaard <dr@jones.dk>2002-02-22 19:43:46 +0000
commit121a207e681946a67bdc9914538503653c8df07c (patch)
tree610d1d287b26a7ca66d1b206cd0cfe28fe33a6df /showlog
parent4cf0d58554a2394ed8e9e6b23173191da4ccfd26 (diff)
showlog: New command to list logfiles with simple options (targeted at local admins).
Diffstat (limited to 'showlog')
-rwxr-xr-xshowlog85
1 files changed, 85 insertions, 0 deletions
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 <dr@jones.dk>
+
+# halt on errors (NB! this is a bashism...)
+set -e
+
+function usage() {
+ echo "Usage: $(basename $0) ftp|web|weberror|mail [<keyword> [<keyword>...]]"
+ 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