From 08074436d6d19363ccda3c76ecd2e989b416c73b Mon Sep 17 00:00:00 2001 From: Patrick McGuire Date: Wed, 13 Oct 2021 17:18:14 -0400 Subject: [PATCH 1/2] working on cleanup.sh --- scripts/cleanup.sh | 7 +++++-- scripts/extract_new_birdsounds.sh | 22 ++-------------------- templates/cleanup.cron | 2 +- 3 files changed, 8 insertions(+), 23 deletions(-) diff --git a/scripts/cleanup.sh b/scripts/cleanup.sh index 27c8998..0b922d6 100755 --- a/scripts/cleanup.sh +++ b/scripts/cleanup.sh @@ -2,5 +2,8 @@ source /etc/birdnet/birdnet.conf cd "${PROCESSED}" || exit 1 -FIND_DATE=*$(date --date="2 days ago" "+%F")* -find . -name "${FIND_DATE}" -exec rm -rfv {} + +empties=($(find ${PROCESSED} -size 57c)) +for i in "${empties[@]}";do + rm -f "${i}" + rm -f "${i/.csv/}" +done diff --git a/scripts/extract_new_birdsounds.sh b/scripts/extract_new_birdsounds.sh index 5fabe83..d337240 100755 --- a/scripts/extract_new_birdsounds.sh +++ b/scripts/extract_new_birdsounds.sh @@ -17,23 +17,6 @@ ANALYZED=${RECS_DIR}/*/*Analyzed # SCAN_DIRS are all directories marked "Analyzed" SCAN_DIRS=($(find ${ANALYZED} -type d | sort )) -# This sets our while loop integer iterator 'a' -- it first checks whether -# there are any extractions, and if so, this instance of the extraction will -# start the 'a' value where the most recent instance left off. -# Ex: If the last extraction file is 189-%date%species.wav, 'a' will be 190. -# Else, 'a' starts at 1 -#if [ "$(find ${EXTRACTED} -name '*.wav' | wc -l)" -ge 1 ];then -# a=$(( $( find "${EXTRACTED}" -name '*.wav' \ -# | awk -F "/" '{print $NF}' \ -# | cut -d'-' -f1 \ -# | sort -n \ -# | tail -n1 ) + 1 )) -#else -# a=1 -#fi - -#echo "Starting numbering at ${a}" - for h in "${SCAN_DIRS[@]}";do # The TMPFILE is created from each .csv file BirdNET creates # within each "Analyzed" directory @@ -50,6 +33,7 @@ for h in "${SCAN_DIRS[@]}";do rm -drf "$(echo ${h} | cut -d'-' -f1-3)" continue fi + # Iterates over each "Analyzed" directory for i in $(find ${h} -name '*csv' | sort );do # Iterates over each '.csv' file found in each "Analyzed" directory @@ -85,8 +69,7 @@ for h in "${SCAN_DIRS[@]}";do NEWSPECIES_BY_COMMON="${EXTRACTED}/By_Common_Name/${COMMON_NAME// /_}" NEWSPECIES_BY_SCIENCE="${EXTRACTED}/By_Scientific_Name/${SCIENTIFIC_NAME// /_}" - # If the extracted file already exists, increment the 'a' variable once - # but move onto the next line of the TMPFILE for extraction. + # If the extracted file already exists, move on if [[ -f "${NEWSPECIES_BYDATE}/${NEWFILE}" ]];then echo "Extraction exists. Moving on" continue @@ -97,7 +80,6 @@ for h in "${SCAN_DIRS[@]}";do # original WAVE file still exists. [[ -f "${h}/${OLDFILE}" ]] || continue - # If a directory does not already exist for the species (by date), # it is created [[ -d "${NEWSPECIES_BYDATE}" ]] || mkdir -p "${NEWSPECIES_BYDATE}" diff --git a/templates/cleanup.cron b/templates/cleanup.cron index 2c805fa..c0b629c 100644 --- a/templates/cleanup.cron +++ b/templates/cleanup.cron @@ -1,4 +1,4 @@ #birdnet -0 1 * * * /usr/local/bin/cleanup.sh &> /dev/null +0/30 * * * * /usr/local/bin/cleanup.sh &> /dev/null #birdnet @reboot /usr/local/bin/cleanup.sh &> /dev/null From edf0a642539babdccb220d0c46b7c0eec52a0692 Mon Sep 17 00:00:00 2001 From: Patrick McGuire Date: Wed, 13 Oct 2021 17:23:23 -0400 Subject: [PATCH 2/2] this is already a lot better --- scripts/cleanup.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/cleanup.sh b/scripts/cleanup.sh index 0b922d6..498f9c4 100755 --- a/scripts/cleanup.sh +++ b/scripts/cleanup.sh @@ -7,3 +7,8 @@ for i in "${empties[@]}";do rm -f "${i}" rm -f "${i/.csv/}" done + +if [[ "$(find ${PROCESSED} | wc -l)" -ge 100 ]];then + ls -1t . | tail -n +100 | xargs -r rm -vv +else +