February 6, 20251 yr The clear drive script from this thread is from 2016, and the author hasn't been to this board since 2017. I found 3 edits needed to clean it up and have it work well for me: 1) The script does not work for unraid >6.9 since it parses the unraid version # wrong. If you are running >=6.10 then change the detection code to this: # check unRAID version v1=`cat /etc/unraid-version` v2="${v1:9:1}" if [[ $v2 -ge 7 ]] then v=" status=progress" else v2="${v1:9:1}${v1:11:2}" if [[ $v2 -ge 610 ]] then v=" status=progress" else v="" fi fi #echo -e "v1=$v1 v2=$v2 v=$v\n" 2) With the larger arrays that are common now, the search for drives is slower than it needs to be. Rather than check for the marker and emptiness at once, splitting that up makes the check much faster: for d in /mnt/disk[1-9]* do #echo -e "ls -A d:$d\n" x=`ls -A $d` #echo $x #echo -e "d:"$d "x:"${x:0:20} # the test for marker if [ "$x" == "$marker" ] then z=`du -s $d` y=${z:0:1} #echo -e "d:"$d "x:"${x:0:20} "y:"$y "z:"$z # the test for emptiness if [ "$y" == "0" ] then found=1 #echo -e "d:"$d "is empty and has the 'clear-me' marker" break fi fi let n=n+1 done 3) The device names have changed from /dev/mdX to /dev/mdXp1. So change the script references from md${d:9} to md${d:9}p1 . There are 5 such references in the script (2 of which are commented out). I'm hesitating to share the full edited script here as I would rather see others validate the above. Edited February 6, 20251 yr by tcharron added link to original script
May 16, 20251 yr I made these changes to the script and it appears to work as expected. A little frustrating that the official documentation references this script and it doesn't actually work.
September 30, 2025Sep 30 On 9/3/2016 at 8:06 PM, RobJ said:Clear an unRAID array data drive (for the Shrink array wiki page) ......Is this script still valid for Unraid V7I tried to use thisthe drive in question instantly shrunk from 4tb to 16gbthen gave an error saying it could not write due to insufficient space
October 1, 2025Oct 1 This thread should now be best ignored and the official documentation used instead:https://docs.unraid.net/unraid-os/using-unraid-to/manage-storage/array-configuration/#removing-data-disks
January 15Jan 15 On 7/17/2016 at 8:43 AM, hernandito said:(Moved from original script thread.) My mini-contribution: CleanDockerLogSize script.This will display the log sizes, clean them, and then displays the result after the cleaning. descriptionClean-up the Docker Log Sizes on your system.(Code removed, see original post)Please understand guys, I am not an expert.I wanted to make this prettier and more informative. Feedback welcome.#!/bin/bash # ============================================================================== # Docker Container Log Cleanup Script # ============================================================================== # This script displays Docker container log sizes before zeroing them # Output shows size in bytes, container name, and total size # Designed for Unraid/Linux systems # ============================================================================== # HTML color code variables for output formatting COLOR_RED="<font color='red'>" COLOR_GREEN="<font color='green'>" COLOR_BLUE="<font color='blue'>" COLOR_END="</font>" COLOR_RED_BOLD="<font color='red'><b>" COLOR_GREEN_BOLD="<font color='green'><b>" COLOR_BLUE_BOLD="<font color='blue'><b>" COLOR_END_BOLD="</b></font>" # Function to display log sizes for all containers display_log_sizes() { docker ps -qa | while read -r container_id; do # Get the log file path for this container log_path=$(docker inspect --format='{{.LogPath}}' "$container_id") # Check if log path exists and is a file if [ -n "$log_path" ] && [ -f "$log_path" ]; then # Get size in bytes size=$(stat -c%s "$log_path" 2>/dev/null) # Get container name name=$(docker ps --format "{{.Names}}" --filter "id=$container_id") # Only include non-zero sizes if [ -n "$size" ] && [ "$size" != "0" ]; then echo "$size|$name" fi fi done | sort -n | awk -F'|' ' { # Store sizes and names in arrays sizes[NR] = $1 names[NR] = $2 total += $1 # Track the maximum width needed len = length($1) if (len > max_width) { max_width = len } } END { # Ensure total width is also considered total_len = length(total) if (total_len > max_width) { max_width = total_len } # Print all entries with dynamic padding for (i = 1; i <= NR; i++) { printf "%0*d bytes = %s\n", max_width, sizes[i], names[i] } # Print separator matching the width of the numbers for (j = 0; j < max_width + 6; j++) { printf "=" } printf "\n" printf "%0*d bytes TOTAL\n", max_width, total }' } # ============================================================================== # Display current log sizes # ============================================================================== echo "Script to display Docker container log sizes in sorted order." echo "Output shows size in bytes, container name, and total size." echo "" echo "${COLOR_BLUE_BOLD}===== Current Log Sizes ===============================================${COLOR_END_BOLD}" echo "" display_log_sizes echo "" # ============================================================================== # Zero out all log files # ============================================================================== echo "${COLOR_GREEN_BOLD}===== Zeroing Logs ====================================================${COLOR_END_BOLD}" echo "" echo "${COLOR_GREEN}Cleaning Logs${COLOR_END}" # Find all Docker log files and zero them out while read -r log; do # Get size in bytes size=$(stat -c%s "$log" 2>/dev/null) # Only include non-zero sizes if [ -n "$size" ] && [ "$size" != "0" ]; then # Extract just the log filename for display filename=$(basename "$log") printf "${COLOR_GREEN}Zeroing out %s${COLOR_END}" "$filename" # Zero out the log file if cat /dev/null > "$log" 2>/dev/null; then echo "${COLOR_GREEN} ... done.${COLOR_END}" else echo "${COLOR_RED_BOLD} ... failed!${COLOR_END_BOLD}" echo "${COLOR_RED_BOLD}Error: Failed to zero out log file. Exiting.${COLOR_END_BOLD}" exit 1 fi fi done < <(find /var/lib/docker/containers/ -name '*.log') echo "${COLOR_GREEN}Cleaning complete!${COLOR_END}" echo ""
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.