From be7f4c0e60a406cc0c7985cfe419bd42aca7ae48 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch> Date: Tue, 2 Nov 2021 15:36:53 +0100 Subject: [PATCH] add deletion of logs --- deploy_app.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/deploy_app.sh b/deploy_app.sh index 05e2c2e..206f651 100755 --- a/deploy_app.sh +++ b/deploy_app.sh @@ -10,6 +10,7 @@ # 2021-05-27 v0.4 <axel.hahn@iml.unibe.ch> FIX first install # 2021-07-08 v0.5 <axel.hahn@iml.unibe.ch> added function "runas" # 2021-11-01 v0.6 <axel.hahn@iml.unibe.ch> save config diffs +# 2021-11-02 v0.7 <axel.hahn@iml.unibe.ch> delete logs keping N files # ====================================================================== @@ -22,6 +23,9 @@ selfdir=$( /bin/pwd ) tmpdir=/var/tmp/imldeployment_packages logdir=/var/log/imldeployment-client +# keep last N logs per project +typeset -i iKeep=10 + wait=0 # wait=1 @@ -253,6 +257,27 @@ function deploy(){ cd $( dirname $0 ) } + +# delete old logfiles keeping the last N files +# param string name of project +function logdelete(){ + local sProfile=$1 + + # order files by time + typeset -i local _iFiles=$( ls -1t ${logdir}/${sProfile}__.* | wc -l ) + + header "DELETE LOGS ${logdir}/${sProfile}__* ... keep $iKeep" + if [ $_iFiles -gt $iKeep ]; then + ls -1t ${logdir}/${sProfile}__.* | sed -n "${iKeep},${_iFiles}p" | while read mylogfile + do + echo -n "deleting " + ls -l "${mylogfile}" && rm -f "${mylogfile}" + done + else + echo SKIP: deletion ... less than $iKeep files found + fi +} + # ---------------------------------------------------------------------- # MAIN # ---------------------------------------------------------------------- @@ -322,6 +347,7 @@ fi for myprofile in $allprofiles do deploy $myprofile | tee ${logdir}/${myprofile}__$(date +%Y-%m-%d__%H%I%S).log + logdelete $myprofile profile= done -- GitLab