From 01205ce0b9d32b98ec0b0171da11c5307e279185 Mon Sep 17 00:00:00 2001 From: Daniel Sosnowski Date: Tue, 2 Dec 2025 10:58:14 +0100 Subject: [PATCH] Added an if instruction for files that are being deleted at the end --- clearCache.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/clearCache.sh b/clearCache.sh index e69de29..2b4fa8b 100644 --- a/clearCache.sh +++ b/clearCache.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +declare -i diskUsage +vhostDir="/var/www/vhosts" + +diskUsage=$(df -h | grep /dev/mapper/tulup--vg-root | awk '{print $5}' | cut -d% -f1) +if [[ $diskUsage -ge 50 ]] +then + + cd "$vhostDir" + + find . -maxdepth 1 -name "*.decostores.*" > "/tmp/subscriptions.txt" + echo -e "Wykryto subskrypcje:\n" + cat /tmp/subscriptions.txt | cut -d/ -f2 + readarray -t subscriptionList < /tmp/subscriptions.txt + + echo -e "\n" + echo -e "Rozpoczynam czyszczenie cache...\n" + + for subscription in "${subscriptionList[@]}" + do + cd "$subscription/httpdocs/shopsystem/application/cache/boxes" + echo -e "CzyszczÄ™ cache w subskrybcji $subscription...\n" + ls -1 > "/tmp/dirList.txt" + readarray -t dirList < /tmp/dirList.txt + for dir in "${dirList[@]}" + do + if [[ -d "$dir" ]] + then + echo -e "Czyszczenie $dir...\n" + cd "$dir" + ls -1 + cd .. + fi + done + cd "$vhostDir" + done + +fi + +if [[ -f "/tmp/subscriptions.txt" ]] && [[ -f "/tmp/dirList.txt" ]] +then + rm -r "/tmp/subscriptions.txt" "/tmp/dirList.txt" +fi \ No newline at end of file