Code: Select all
#!/bin/bash
#file used to control zoneminder
ZM_CONTROL_CMD="/etc/init.d/zm"
#ZM_CONTROL_CMD="/usr/bin/zmpkg.pl"
# "y" will cause zm to restart when logs are rotated
# "n" rotate logs without restarting zm
DO_STOP_ZM_YN="n"
#zm log directory
ZM_LOG_DIR="/var/log/zm"
#log files to rotate
ZM_LOG_FILES="zmaudit.log zmdc.log zmfilter.log zmpkg.log zmwatch.log"
#number of old logs to keep
NUM_OF_OLD_LOGS="4"
for i in `seq ${NUM_OF_OLD_LOGS} -1 1`
do
for fil in `ls ${ZM_LOG_DIR}/*${i}.bz2 2> /dev/null`
do
base=`echo $fil | cut -d "." -f1,2`
let x=${i}+1
[ ${NUM_OF_OLD_LOGS} -eq ${i} ] && rm ${fil} 2> /dev/null ||
mv ${fil} ${base}.${x}.bz2 2> /dev/null
done
done
[ ${DO_STOP_ZM_YN} == "y" ] && ${ZM_CONTROL_CMD} stop &> /dev/null
for i in `echo ${ZM_LOG_FILES}`
do
[ -e ${ZM_LOG_DIR}/${i} ] &&
mv ${ZM_LOG_DIR}/${i} ${ZM_LOG_DIR}/${i}.1 &&
bzip2 ${ZM_LOG_DIR}/${i}.1 ||
true
done
[ ${DO_STOP_ZM_YN} == "y" ] && ${ZM_CONTROL_CMD} start &> /dev/null