Skip to content
Snippets Groups Projects
Commit be7f4c0e authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

add deletion of logs

parent 9e590abf
Branches
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
# 2021-05-27 v0.4 <axel.hahn@iml.unibe.ch> FIX first install # 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-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-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 ) ...@@ -22,6 +23,9 @@ selfdir=$( /bin/pwd )
tmpdir=/var/tmp/imldeployment_packages tmpdir=/var/tmp/imldeployment_packages
logdir=/var/log/imldeployment-client logdir=/var/log/imldeployment-client
# keep last N logs per project
typeset -i iKeep=10
wait=0 wait=0
# wait=1 # wait=1
...@@ -253,6 +257,27 @@ function deploy(){ ...@@ -253,6 +257,27 @@ function deploy(){
cd $( dirname $0 ) 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 # MAIN
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
...@@ -322,6 +347,7 @@ fi ...@@ -322,6 +347,7 @@ fi
for myprofile in $allprofiles for myprofile in $allprofiles
do do
deploy $myprofile | tee ${logdir}/${myprofile}__$(date +%Y-%m-%d__%H%I%S).log deploy $myprofile | tee ${logdir}/${myprofile}__$(date +%Y-%m-%d__%H%I%S).log
logdelete $myprofile
profile= profile=
done done
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment