From d469b1a7595951222d4d3e3d7134dd22c72b94fa Mon Sep 17 00:00:00 2001 From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com> Date: Mon, 9 May 2022 10:35:34 -0400 Subject: [PATCH] Prevent disk_check from erasing our "Best Recordings" let me know what you think @mcguirepr89 --- scripts/disk_check.sh | 18 ++++++++++++++++-- scripts/stats.php | 12 ++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/scripts/disk_check.sh b/scripts/disk_check.sh index 8fb7973..585a391 100755 --- a/scripts/disk_check.sh +++ b/scripts/disk_check.sh @@ -7,8 +7,22 @@ if [ "${used//%}" -ge 95 ]; then case $FULL_DISK in purge) echo "Removing oldest data" - rm -drfv "$(find ${EXTRACTED}/By_Date/* -maxdepth 1 -type d -prune \ - | sort -r | tail -n1)";; + cd ${EXTRACTED}/By_Date/ + + iter=0 + for i in */*/*; do + if [ $iter -ge 250 ]; then + break + fi + if ! grep -qxFe "$i" $HOME/BirdNET-Pi/scripts/disk_check_exclude.txt; then + rm "$i" + fi + ((iter++)) + done + find ${EXTRACTED}/By_Date/ -empty -type d -delete;; + + #rm -drfv "$(find ${EXTRACTED}/By_Date/* -maxdepth 1 -type d -prune \ + # | sort -r | tail -n1)";; keep) echo "Stopping Core Services" /usr/local/bin/stop_core_services.sh;; esac diff --git a/scripts/stats.php b/scripts/stats.php index d546219..230a54a 100644 --- a/scripts/stats.php +++ b/scripts/stats.php @@ -52,6 +52,11 @@ if(isset($_GET['species'])){ } $result3 = $statement3->execute(); } + +$user = shell_exec("awk -F: '/1000/{print $1}' /etc/passwd"); +$home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd"); +$home = trim($home); +file_put_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", ""); ?> @@ -157,6 +162,10 @@ while($results=$result->fetchArray(SQLITE3_ASSOC)) $comname = preg_replace('/ /', '_', $results['Com_Name']); $comname = preg_replace('/\'/', '', $comname); $filename = "/By_Date/".$results['Date']."/".$comname."/".$results['File_Name']; + +$excludefile = fopen($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", "a") or die("Unable to open file!"); +$txt = $results['Date']."/".$comname."/".$results['File_Name']."\n".$results['Date']."/".$comname."/".$results['File_Name'].".png\n"; +fwrite($excludefile, $txt); ?>
@@ -174,5 +183,4 @@ $filename = "/By_Date/".$results['Date']."/".$comname."/".$results['File_Name']; - - + \ No newline at end of file