Skip to content
Snippets Groups Projects
Commit 30580daa authored by Jörg Sachse's avatar Jörg Sachse
Browse files

refactor: simpler find conditions

parent 6fed5c13
No related branches found
No related tags found
1 merge request!2merge feat_ND-2363_ND-2323 into master
Pipeline #3403 passed
...@@ -8,7 +8,9 @@ START_YEAR="2015" ...@@ -8,7 +8,9 @@ START_YEAR="2015"
CURRENT_YEAR="$( date +%Y )" CURRENT_YEAR="$( date +%Y )"
PREVIOUS_YEAR="$(( CURRENT_YEAR - 1 ))" 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") ]] && \ [[ (! ${APP} =~ "disapp") && (! ${APP} =~ "subapp") && (! ${APP} =~ "subapp_webservice") ]] && \
echo 'ERROR: $1 needs to be one of "disapp", "subapp" or "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/" ...@@ -23,19 +25,20 @@ chown -R processing.processing "/var/log/${APP}/old/"
# move all old logfiles # move all old logfiles
for YEAR in $( seq ${START_YEAR} ${PREVIOUS_YEAR} ); do for YEAR in $( seq ${START_YEAR} ${PREVIOUS_YEAR} ); do
if [[ "${APP}" == "disapp" ]]; then 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 fi
if [[ "${APP}" == "subapp" ]]; then 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 # We run `find` before `mv` to make sure that `mv` doesn't fail if there are no files to move
if [[ -n $( find ./ -maxdepth 1 -name "Protokoll_SLUBArchiv_FEHLER-${YEAR}*.log" ) ]]; then mv "Protokoll_SLUBArchiv_FEHLER-${YEAR}*.log" "old/${YEAR}/"; fi if find ./ -maxdepth 1 -name "Protokoll_SLUBArchiv_Erfolgreich-${YEAR}*.log" > /dev/null; then mv "Protokoll_SLUBArchiv_Erfolgreich-${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 find ./ -maxdepth 1 -name "Protokoll_SLUBArchiv_FEHLER-${YEAR}*.log" > /dev/null; then mv "Protokoll_SLUBArchiv_FEHLER-${YEAR}*.log" "old/${YEAR}/"; fi
if [[ -n $( find ./ -maxdepth 1 -name "subapp.log.${YEAR}-*.lz" ) ]]; then mv "subapp.log.${YEAR}-*.lz" "old/${YEAR}/"; fi if find ./ -maxdepth 1 -name "sips.log.${YEAR}-*.lz" > /dev/null; then mv "sips.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 find ./ -maxdepth 1 -name "subapp.log.${YEAR}-*.lz" > /dev/null; then mv "subapp.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 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 fi
if [[ "${APP}" == "subapp_webservice" ]]; then 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 fi
done done
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment