diff --git a/files/usr/local/bin/move_old_logs.sh b/files/usr/local/bin/move_old_logs.sh index b489aee25b9de6622c87dbe4716ef31682d5c8aa..25377bc47e0678b5987f97b3288fe258516f573e 100644 --- a/files/usr/local/bin/move_old_logs.sh +++ b/files/usr/local/bin/move_old_logs.sh @@ -8,7 +8,9 @@ START_YEAR="2015" CURRENT_YEAR="$( date +%Y )" PREVIOUS_YEAR="$(( CURRENT_YEAR - 1 ))" -[[ -n ${1} ]] && APP=${1} +[[ -n ${1} ]] && APP="${1}" +# shellcheck disable=SC2016 +# ...because we don't want the expansion to happen in the log message [[ (! ${APP} =~ "disapp") && (! ${APP} =~ "subapp") && (! ${APP} =~ "subapp_webservice") ]] && \ echo 'ERROR: $1 needs to be one of "disapp", "subapp" or "subapp_webservice"' @@ -23,19 +25,20 @@ chown -R processing.processing "/var/log/${APP}/old/" # move all old logfiles for YEAR in $( seq ${START_YEAR} ${PREVIOUS_YEAR} ); do if [[ "${APP}" == "disapp" ]]; then - if [[ -n $( find ./ -maxdepth 1 -name "disapp.log.${YEAR}-*.lz" ) ]]; then mv "disapp.log.${YEAR}-*.lz" "old/${YEAR}/"; fi + if find ./ -maxdepth 1 -name "disapp.log.${YEAR}-*.lz"; then mv "disapp.log.${YEAR}-*.lz" "old/${YEAR}/"; fi fi if [[ "${APP}" == "subapp" ]]; then - if [[ -n $( find ./ -maxdepth 1 -name "Protokoll_SLUBArchiv_Erfolgreich-${YEAR}*.log" ) ]]; then mv "Protokoll_SLUBArchiv_Erfolgreich-${YEAR}*.log" "old/${YEAR}/"; fi - if [[ -n $( find ./ -maxdepth 1 -name "Protokoll_SLUBArchiv_FEHLER-${YEAR}*.log" ) ]]; then mv "Protokoll_SLUBArchiv_FEHLER-${YEAR}*.log" "old/${YEAR}/"; fi - if [[ -n $( find ./ -maxdepth 1 -name "sips.log.${YEAR}-*.lz" ) ]]; then mv "sips.log.${YEAR}-*.lz" "old/${YEAR}/"; fi - if [[ -n $( find ./ -maxdepth 1 -name "subapp.log.${YEAR}-*.lz" ) ]]; then mv "subapp.log.${YEAR}-*.lz" "old/${YEAR}/"; fi - if [[ -n $( find ./ -maxdepth 1 -name "producer_mails.log.${YEAR}-*.lz" ) ]]; then mv "producer_mails.log.${YEAR}-*.lz" "old/${YEAR}/"; fi - if [[ -n $( find ./ -maxdepth 1 -name "staff_mails.log.${YEAR}-*.lz" ) ]]; then mv "staff_mails.log.${YEAR}-*.lz" "old/${YEAR}/"; fi + # We run `find` before `mv` to make sure that `mv` doesn't fail if there are no files to move + if find ./ -maxdepth 1 -name "Protokoll_SLUBArchiv_Erfolgreich-${YEAR}*.log" > /dev/null; then mv "Protokoll_SLUBArchiv_Erfolgreich-${YEAR}*.log" "old/${YEAR}/"; fi + if find ./ -maxdepth 1 -name "Protokoll_SLUBArchiv_FEHLER-${YEAR}*.log" > /dev/null; then mv "Protokoll_SLUBArchiv_FEHLER-${YEAR}*.log" "old/${YEAR}/"; fi + if find ./ -maxdepth 1 -name "sips.log.${YEAR}-*.lz" > /dev/null; then mv "sips.log.${YEAR}-*.lz" "old/${YEAR}/"; fi + if find ./ -maxdepth 1 -name "subapp.log.${YEAR}-*.lz" > /dev/null; then mv "subapp.log.${YEAR}-*.lz" "old/${YEAR}/"; fi + if find ./ -maxdepth 1 -name "producer_mails.log.${YEAR}-*.lz" > /dev/null; then mv "producer_mails.log.${YEAR}-*.lz" "old/${YEAR}/"; fi + if find ./ -maxdepth 1 -name "staff_mails.log.${YEAR}-*.lz" > /dev/null; then mv "staff_mails.log.${YEAR}-*.lz" "old/${YEAR}/"; fi fi if [[ "${APP}" == "subapp_webservice" ]]; then - if [[ -n $( find ./ -maxdepth 1 -name "webservice.log.${YEAR}-*.lz" ) ]]; then mv "webservice.log.${YEAR}-*.lz" "old/${YEAR}/"; fi + if find ./ -maxdepth 1 -name "webservice.log.${YEAR}-*.lz"; then mv "webservice.log.${YEAR}-*.lz" "old/${YEAR}/"; fi fi done