diff --git a/deploy_app.sh b/deploy_app.sh index 05e2c2e0aa54846b9887d774e14f53f4ac47183d..206f6515d532c35993a2e33aa848cca842e8e65b 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