Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Additional Scripts For User.Scripts Plugin

Featured Replies

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 by tcharron
added link to original script

  • 3 months later...
  • Replies 604
  • Views 302.9k
  • Created
  • Last Reply

Top Posters In This Topic

Most Popular Posts

  • Clear an unRAID array data drive  (for the Shrink array wiki page)   Mod note: this script usually takes a much longer than normal time to clear a drive with newer Unraid releases, recommend

  • SpaceInvaderOne
    SpaceInvaderOne

    Backup vm xml files and ovmf nvram files.   This script backs up vm xml files and ovmf nvram files to a folder of your choice. they are put into a dated folder. Just set the location in the scr

  • Well, this was easier than I thought. This is a pretty basic script that runs the 'tree' command against each of your array disks, creating a txt of their contents. My primary purpose for this is to s

Posted Images

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.

  • 4 months later...
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 V7

I tried to use this

the drive in question instantly shrunk from 4tb to 16gb

then gave an error saying it could not write due to insufficient space

  • 3 months later...
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.

 

description

Clean-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.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.