Skip to content
Snippets Groups Projects
Commit d0bdbd23 authored by david_williams's avatar david_williams
Browse files

improve daily cleanup scripts

parent 6030ce00
No related branches found
No related tags found
No related merge requests found
......@@ -24,81 +24,6 @@ fi
# = = = = = = = = = = = = = = = = = = = = =
function removeIf ()
{
# echo "arg: $1";
if [ -z $1 ]
then
echo " This script requires an argument. " ;
return 1;
fi
foundDirectory=$1
# should already be in foundDirectory, if execDir used
cd $foundDirectory
# adding a few "should never happen" errror checks
if [ -d $foundDirectory ]
then
rm -fr $foundDirectory
echo " removed: $foundDirectory";
else
echo "ERROR: the foundDirectory, $foundDirectory, is not a directory"
fi
}
function removeArtifactsIf ()
{
# echo "arg: $1";
if [ -z $1 ]
then
echo " This script requires an argument. " ;
return 1;
fi
foundDirectory=$1
nSave=$2
if [ -z $nSave ]
then
nSave=1;
fi
# should already be in foundDirectory, if execDir used
cd $foundDirectory
# move up one so we can examine syblings
cd ..
currentDirectory=`pwd`
echo " current working directory: $currentDirectory";
ndirs=`ls -lA | wc -l`
ndirs=$(($ndirs - 1)); # don't count the "totals" line
# echo "NDirs: $ndirs"
# if only one left, do not remove it, no matter how old
# or, as improved ... if less than or equal to nSave is left, do not remove
if [ $ndirs -le $nSave ]
then
exit 0;
fi
# This is unexpected, since otherwise this method should not have been called.
# So, this check is just a safety check.
if [ $ndirs -lt 1 ]
then
exit 101;
fi
# ok, it is old, and not the only one left
# adding a few "should never happen" errror checks
if [ -d $foundDirectory ]
then
rm -fr $foundDirectory
echo " removed: $foundDirectory";
else
echo "ERROR: the foundDirectory, $foundDirectory, is not a directory"
fi
}
# requires parent Directiory as first argument
# if nDays not specified as second argument, then 0 is assumed
......@@ -141,9 +66,9 @@ before=`find ${parentDir} -mindepth 2 -maxdepth 2 | wc -l`;
echo " number of directories before cleaning: ${before}";
# empty directories often result from "bad builds". We remove those no matter how old
find ${parentDir} -mindepth 2 -maxdepth 3 -type d -empty -exec rm -fr '{}' \;
find ${parentDir} -mindepth 2 -maxdepth 3 -type d -empty -execdir rm -fr '{}' \;
# now remove old ones
find ${parentDir} -mindepth 2 -maxdepth 2 -type d -atime +$ndays -execdir removeArtifactDirIf '{}' $saveAtLeast \;
find ${parentDir} -mindepth 2 -maxdepth 2 -type d -atime +$ndays -execdir ${RELENG_CONTROL}/removeArtifactDirIf.sh '{}' $saveAtLeast \;
after=`find ${parentDir} -mindepth 2 -maxdepth 2 | wc -l`;
echo " number of directories after cleaning: ${after}";
......@@ -183,9 +108,9 @@ before=`find ${parentDir} -mindepth 1 -maxdepth 1 | wc -l`;
echo " number of directories before cleaning: ${before}";
# empty directories often result from "bad builds". We remove those no matter how old
find ${parentDir} -mindepth 1 -maxdepth 2 -type d -empty -exec rm -fr '{}' \;
find ${parentDir} -mindepth 1 -maxdepth 2 -type d -empty -execdir rm -fr '{}' \;
# now remove old ones
find ${parentDir} -mindepth 1 -maxdepth 1 -type d -atime +$ndays -exec removeIf '{}' \;
find ${parentDir} -mindepth 1 -maxdepth 1 -type d -atime +$ndays -execdir ${RELENG_CONTROL}/removeIf.sh '{}' \;
after=`find ${parentDir} -mindepth 1 -maxdepth 1 | wc -l`;
echo " number of directories after cleaning: ${after}";
......@@ -227,7 +152,7 @@ before=`find ${parentDir} | wc -l`;
echo " number of directories and files before cleaning: ${before}";
# remove all old directories and files
find ${parentDir} -atime +$ndays -exec rm -fr '{}' \;
find ${parentDir} -atime +$ndays -execdir rm -fr '{}' \;
after=`find ${parentDir} | wc -l`;
echo " number of directories and files after cleaning: ${after}";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment