diff --git a/disk-check.sh b/disk-check.sh index ca8fd72..d2679b0 100644 --- a/disk-check.sh +++ b/disk-check.sh @@ -1,5 +1,7 @@ #!/bin/bash +echo "Starting disk space report... This may take a few minutes." + # Function to estimate the size of the apt cache estimate_apt_cache_size() { echo "Estimating the size of the apt cache:" @@ -35,11 +37,29 @@ estimate_docker_volumes_size() { echo } +# Function to check and suggest logrotate for large Docker logs +check_docker_logs() { + echo "Checking Docker logs for large files..." + large_logs=$(sudo find /var/lib/docker/containers/ -type f -name "*.log" -size +1G) + if [ -n "$large_logs" ]; then + echo "The following Docker logs are larger than 1GB:" + echo "$large_logs" + echo + echo "Consider setting up logrotate to manage Docker logs." + echo "To truncate all Docker logs, run:" + echo 'sudo find /var/lib/docker/containers/ -type f -name "*.log" -exec truncate -s 0 {} \;' + echo + else + echo "No large Docker logs found." + echo + fi +} + # Function to list directories consuming more than a specified size list_large_directories() { local directory=$1 local size_limit=$2 - echo "Directories in $directory consuming more than $size_limit:" + echo "Directories in $directory consuming more than ${size_limit}GB:" sudo du -ah $directory 2>/dev/null | awk -v limit=$size_limit '{ size=$1; unit=substr(size, length(size)); size_val=substr(size, 1, length(size)-1); @@ -58,6 +78,9 @@ estimate_journal_size estimate_tmp_size estimate_docker_volumes_size +# Check Docker logs +check_docker_logs + # List large directories echo "Listing directories consuming more than 5GB and 10GB:" list_large_directories / 5