reconf the master and common scripts and all unraid essential scripts# Please enter the commit message for your changes. Lines starting
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
#-----------------------------------------------------------------------------------------------
|
||||
# Clear Unraid system logs and Docker container logs safely
|
||||
#-----------------------------------------------------------------------------------------------
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR/../common.sh"
|
||||
|
||||
# Load central config
|
||||
load_master_conf
|
||||
|
||||
# Parse CLI args (supports --dry-run)
|
||||
parse_args "$@"
|
||||
|
||||
# Colors for output
|
||||
RED="\033[0;31m"
|
||||
GREEN="\033[0;32m"
|
||||
YELLOW="\033[1;33m"
|
||||
RESET="\033[0m"
|
||||
|
||||
# Log files to clear (can also be overridden in Master.conf)
|
||||
LOG_FILES=("${LOG_FILES[@]:-/var/log/syslog /var/log/messages /var/log/dmesg}")
|
||||
|
||||
# Require root
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
printf "${RED}❌ Please run as root.${RESET}\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${YELLOW}Starting log cleanup...${RESET}\n"
|
||||
|
||||
# Functions
|
||||
clear_file() {
|
||||
local file="$1"
|
||||
if [ ! -f "$file" ]; then
|
||||
printf "${RED}Not found:${RESET} %s\n" "$file"
|
||||
return
|
||||
fi
|
||||
|
||||
if [ "$DRY_RUN" = true ]; then
|
||||
printf "${YELLOW}Would clear:${RESET} %s\n" "$file"
|
||||
else
|
||||
: > "$file"
|
||||
printf "${GREEN}Cleared:${RESET} %s\n" "$file"
|
||||
fi
|
||||
}
|
||||
|
||||
clear_docker_logs() {
|
||||
if [ ! -d /var/lib/docker/containers ]; then
|
||||
printf "${RED}Docker containers directory not found. Skipping Docker log cleanup.${RESET}\n"
|
||||
return
|
||||
fi
|
||||
|
||||
local files
|
||||
files=$(find /var/lib/docker/containers/ -name "*-json.log" 2>/dev/null)
|
||||
for file in $files; do
|
||||
if [ "$DRY_RUN" = true ]; then
|
||||
printf "${YELLOW}Would clear Docker log:${RESET} %s\n" "$file"
|
||||
else
|
||||
: > "$file"
|
||||
printf "${GREEN}Cleared Docker log:${RESET} %s\n" "$file"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# MAIN
|
||||
for log in "${LOG_FILES[@]}"; do
|
||||
clear_file "$log"
|
||||
done
|
||||
|
||||
clear_docker_logs
|
||||
|
||||
if [ "$DRY_RUN" = true ]; then
|
||||
printf "\n${YELLOW}🧪 Dry run complete. No files were cleared.${RESET}\n"
|
||||
else
|
||||
printf "\n${GREEN}🎉 Done clearing logs.${RESET}\n"
|
||||
fi
|
||||
Reference in New Issue
Block a user