#!/bin/sh #---------------------------------------------------------------------------- # rsyslogd-tools-create-rotate-conf generate logrotate files # # Copyright (c) 2001-2022 Ansgar Puester # # Creation: 07.12.2021 ap # Last Update: $Id$ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- # include eislib . /var/install/include/eislib pgmname=$0 # set variables basefile=/etc/config.d/base rsyslogdfile=/etc/config.d/rsyslogd iobuffersize='64k' # --------------------------------------------------------------------------- # get logfile compression extension from compresscmd in /etc/logrotate.conf # --------------------------------------------------------------------------- get_logfile_comp_extension () { # compresscmd including path compresscmd=$(grep ^compresscmd /etc/logrotate.conf | cut -f2 -d' ') # strip path compresscmd=$(echo $compresscmd | sed "s/.*\///") case "$compresscmd" in 'xz') # xz compression comp_extension='xz' ;; '') # default gzip comp_extension='gz' ;; *) # unknown ;; esac } #------------------------------------------------------------------------------- # create rsyslogd logrotate configuration #------------------------------------------------------------------------------- create_rsyslogd_logrotate_config() { [ "$act_rule" -le 9 ] && act_num='0' act_num="$act_num$act_rule" ACT_ROTATE_FILE="/etc/logrotate.d/rsyslogd_dyn_$act_num" #Test ACT_ROTATE_FILE="/tmp/logtest/rsyslogd_dyn_$act_num" mecho --info "Removing old rsyslogd logrotate file" rm -f $act_logrotate_file act_int='daily' act_count=10 act_pre='' act_post='/etc/init.d/rsyslogd ––quiet restart' if [ "$act_name" = 'ALL' ] then act_find_name='' else act_find_name=" -name $act_name" fi # search directory, avoid files ending with .${comp_extension} act_filelist=$(find $act_path -type f$act_find_name | grep -v "\.${comp_extension}\$" | sort) #Test echo "act_filelist=$act_filelist" if [ -z "$act_filelist" ] then mecho --error "Could not find any file!" exit 1 fi # act_rotate_mode is std { echo "#-------------------------------------------------------------------------------" echo "# $ACT_ROTATE_FILE file generated by $pgmname" echo "#" echo "# Do not edit this file, edit $rsyslogdfile" echo "# Creation date: `date`" echo "#-------------------------------------------------------------------------------" echo "$act_filelist {" echo " $act_int" echo ' missingok' echo " rotate $act_count" echo ' compress' echo ' notifempty' if [ ! "$act_pre" = '' ] then echo ' prerotate' echo " $act_pre" echo ' endscript' fi if [ ! "$act_post" = '' ] then echo ' postrotate' echo " $act_post" echo ' endscript' fi echo '}' } > $ACT_ROTATE_FILE } # --------------------------------------------------------------------------- # main # --------------------------------------------------------------------------- # $1 RSYSLOGD_RULE_N # $2 pathname # $3 filename / ALL if [ ! "$#" = 3 ] then mecho --error "Wrong number of parameters (3/$#)" mecho "Usage:" mecho " $0 RSYSLOGD_RULE_N pathname filename" mecho " RSYSLOGD_RULE_N: RSYSLOGD_RULE_N of rule using dynamic file" mecho " pathname: Path to search" mecho " filename: Filename to search for" mecho " ALL use all files" exit 1 fi act_rule=$1 act_path=$2 act_name=$3 # Check START_RSYSLOGD if [ "$START_RSYSLOGD" = 'no' ] then mecho --warn "START_RSYSLOGD was set to 'no'" mecho --info "????" else # check RSYSLOGD_CONFIGURATION if [ "$RSYSLOGD_CONFIGURATION" = 'manual' ] then mecho --warn "RSYSLOGD_CONFIGURATION was set to 'manual', no configuration will be created" else get_logfile_comp_extension create_rsyslogd_logrotate_config fi fi mecho --info "Finished" exit