ZM-Logs redirect to syslog

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
Post Reply
2tomcats
Posts: 13
Joined: Sat Oct 30, 2004 10:59 am

ZM-Logs redirect to syslog

Post by 2tomcats »

Dear all,
as I like to get all logging centralized I've wrote a little (dirty) script to parse ZMs internal logs like 'zmfilter.log' to syslog. In case someone might find this usefull:

Code: Select all

#!/bin/bash

#################################################
# really dirty hack to redirect ZMs internal logs to syslog
#
# enviroment    : Console
# Depends on    : logger, tail, wc, grep
# written       : 2004-11-08
# last modified : 2004-11-09
# Author        : Uli Wachowitz
# Status        : 0.0.1

# define your logs
LOGDIR="/tmp"
LOGFILE="
zmaudit.log
zmdc.log
zmfilter.log
zmpkg.log
zmwatch.log
"

### no changes beyond this line ###

# check if dependancies are ok, otherwise exit
DEPEND="
logger
tail
wc
grep
"

for i in $DEPEND; do
	if [ "$(which $i)" == "" ]; then
		echo "'$i' not found, exiting"
		exit
	fi
done

# create a new, renamed link to the logger binary to avoid conflicts if we kill it
# and there is another logger already running
[ ! -x /usr/bin/zm_logger.bin ] && ln -s $(which logger) /usr/bin/zm_logger.bin
LOGGER_BIN=$(which zm_logger.bin)

# check if the linking was successfull, otherwise exit
if [ "$LOGGER_BIN" == "" ]; then
	echo "'/usr/bin/zm_logger.bin' does not exist, exiting"
	exit
fi

StartLogging() {
	# check if this is the only instance of this tool. If there is another one 
	# alreday running, exit
	if [ "$(ps -A| grep zm_logger.bin | wc -l)" -gt "0" ]; then
		echo
		echo "ERROR: There is another 'zm_logging' active"
		echo "Use '$0 stop' first to stop all running instances to avoid problems"
		echo
		exit
	fi	

	# here we go
	cd $LOGDIR

	# ugly, ugly, ugly
	# this will create 2 processes of 'zm_logger.sh' and 1 process of 'zm_logger.bin'
	# for each of the monitored logfiles
	# But this is the only way to get logger write the names of the logfiles
	# in front of the entries
	# Nonetheless, the impact on sytemload is quite small
	for i in $LOGFILE; do
		nohup `tail -f -n 0 $i | $LOGGER_BIN -t $i --` &
	done

	$LOGGER_BIN "zm_logger.sh started"
	return
	}

Usage() {
	echo
	echo "USAGE: $0 [start|stop]"
	echo
	exit
	return
	}
	
case $1 in
	stop)	$LOGGER_BIN "zm_logger.sh stopped"
		killall -9 zm_logger.bin
		killall -9 zm_logger.sh
		;;
		
	start)	StartLogging
		;;
		
	*)	Usage
		;;
esac
Use it at your own risk ;-)

Uli
Post Reply