Update clean-lxcs.sh

code refactoring
This commit is contained in:
tteckster 2023-01-28 16:16:55 -05:00 committed by GitHub
parent 5328b66cdf
commit 24eb8ad256
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -18,6 +18,7 @@ GN=$(echo "\033[1;92m")
CL=$(echo "\033[m") CL=$(echo "\033[m")
clear clear
header_info header_info
echo -e "\n ${RD} USE AT YOUR OWN RISK. Deleting logs/cache may result in some apps/services broken!${CL} \n"
while true; do while true; do
read -p "This Will Clean logs, cache and update apt lists on all LXC Containers. Proceed(y/n)?" yn read -p "This Will Clean logs, cache and update apt lists on all LXC Containers. Proceed(y/n)?" yn
case $yn in case $yn in
@ -28,13 +29,13 @@ while true; do
done done
clear clear
containers=$(pct list | tail -n +2 | cut -f1 -d' ') containers=$(pct list | tail -n +2 | cut -f1 -d' ')
function clean_container() { function clean_container() {
container=$1 container=$1
clear clear
header_info header_info
echo -e "${BL}[Info]${GN} Cleaning${BL} $container${CL} \n" name=`pct exec $container hostname`
pct exec $container -- bash -c "apt-get -y autoremove && apt-get -y autoclean && rm -rf /var/{cache,log}/* /var/lib/apt/lists/* && apt-get update" echo -e "${BL}[Info]${GN} Cleaning ${name} ${CL} \n"
pct exec $container -- bash -c "apt-get -y --purge autoremove && apt-get -y autoclean && bash <(curl -fsSL https://github.com/tteck/Proxmox/raw/dev/misc/clean.sh) && rm -rf /var/lib/apt/lists/* && apt-get update"
} }
read -p "Skip stopped containers? " -n 1 -r read -p "Skip stopped containers? " -n 1 -r
echo echo
@ -68,4 +69,4 @@ done
wait wait
clear clear
header_info header_info
echo -e "${GN} Finished, All Containers Cleaned. ${CL} \n" echo -e "${GN} Finished, Containers Cleaned. ${CL} \n"