#!/bin/sh #---------------------------------------------------------------------------- # /var/install/bin/rsyslogd-tools-test-epurge rsyslogd Test dbpurge # # Copyright (c) 2001-2022 Ansgar Puester # # Creation: 12.08.2017 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 #include rsyslogdlib . /var/install/include/rsyslogdlib ASK=/var/install/bin/ask CAT=/bin/cat RM=/bin/rm MKTEMP=/bin/mktemp # include config_shlib . /var/install/bin/config_shlib # set package name package_name=rsyslogd # include package configuration . /etc/config.d/${package_name} syslogdb="${RSYSLOGD_MYSQL_DB_NAME}" pgmname=`basename $0` # set variables rsyslogdfile=/etc/config.d/$package_name # rsyslogd working directory rsyslog_workdirectory=/usr/lib/rsyslog/workdir # directory for rsyslogd logrotate skripts rsyslog_skripts="${rsyslog_workdirectory}/rsyslog_skripts" # --------------------------------------------------------------------------- # Test Configuration # --------------------------------------------------------------------------- test_configuration() { [ "$answer" -le 9 ] && act_num='0' act_num="$act_num$answer" mecho "Generated select file:" mecho cat ${rsyslog_workdirectory}/rsyslog_skripts/select_exp${act_num}.sql mecho anykey mecho "Select file output:" mecho act_status=$(${mysql_basedir}/mysql \ --socket=${mysql_socket} \ --skip-column-names \ -e "USE ${syslogdb}; source ${rsyslog_skripts}/select_exp${act_num}.sql;" ) ${mysql_basedir}/mysql \ --socket=${mysql_socket} \ --skip-column-names \ -e "USE ${syslogdb}; source ${rsyslog_skripts}/select_exp${act_num}.sql;" act_count=$(echo "$act_status" | grep 'total') act_purge=$(echo "$act_status" | grep 'old') act_count=$(echo "$act_count" | cut -f2) act_purge=$(echo "$act_purge" | cut -f2) mecho mecho --warn "The Delete file will delete $act_purge rows!" mecho } # --------------------------------------------------------------------------- # main # --------------------------------------------------------------------------- main() { clrhome mecho mecho mecho --info "rsyslogd Test DBPurge expert configurations." mecho if [ "$RSYSLOGD_MYSQL_DB_USE" = 'no' ]; then mecho --error "RSYSLOGD_MYSQL_DB_USE was set to 'no', no action possible." anykey exit 1 fi check_required_package "${RSYSLOGD_MYSQL_DB_PACKAGE}" RC=$? if [ "$RC" = 1 ];then anykey exit 1 fi get_defaults "${RSYSLOGD_MYSQL_DB_PACKAGE}" RC=$? if [ "$RC" = 1 ];then anykey exit 1 fi if [ ${RSYSLOGD_MYSQL_DB_PACKAGE} = 'Remote' ]; then mecho --error "Error illegal action for remote database." mecho --error " You have to work directly on the remote server!" anykey exit 1 fi if [ "$RSYSLOGD_DBPURGE_EXPERT" = 'yes' ] then techo --begin '4 15 7 5 19 6 24' techo --row "No." "Name" "Active" "Keep" "Column" "Op" "Value" idx=1 while [ "$idx" -le "$RSYSLOGD_DBPURGE_N" ] do eval act_name='$RSYSLOGD_DBPURGE_'${idx}'_NAME' [ "$act_name" = '' ] && act_name='...' eval act_active='$RSYSLOGD_DBPURGE_'${idx}'_ACTIVE' eval act_schedule='$RSYSLOGD_DBPURGE_'${idx}'_SCHEDULE' eval act_keep_days='$RSYSLOGD_DBPURGE_'${idx}'_KEEP_DAYS' eval act_column='$RSYSLOGD_DBPURGE_'${idx}'_COLUMN' eval act_operation='$RSYSLOGD_DBPURGE_'${idx}'_OPERATION' eval act_value='$RSYSLOGD_DBPURGE_'${idx}'_VALUE' techo --row $idx "$act_name" $act_active $act_keep_days $act_column $act_operation $act_value idx=`expr $idx + 1` done techo --end mecho _ask_tmpfile=$(/bin/mktemp -t ask.XXXXXXXXX) /var/install/bin/ask "Select configuration" "" "1-$RSYSLOGD_DBPURGE_N" "^$=Return" "0=Exit" > ${_ask_tmpfile} rc=${?} read answer < ${_ask_tmpfile} rm -f ${_ask_tmpfile} # if ask break, ask returned 255 if [ ${rc} = 255 ] then answer=0 fi case "${answer}" in '') exit 0 ;; 0) exit 127 ;; *) eval act_active='$RSYSLOGD_DBPURGE_'${answer}'_ACTIVE' if [ "$act_active" = 'no' ] then mecho --warn "Configuration ${answer} is not active." fi test_configuration ;; esac else mecho --warn "RSYSLOGD_DBPURGE_EXPERT is set to 'no'." mecho --warn "Not tests possible." fi anykey } # --------------------------------------------------------------------------- # call function main # --------------------------------------------------------------------------- main "${@}" # --------------------------------------------------------------------------- # end # ---------------------------------------------------------------------------