Disk Space for Logs

I’ve added a check for this as well.

Both merged to stable.

This seems like a good idea. Should we delete the largest file or a specific log file that may be less important? I guess we dont know if the latter will free up enough space…

This would find the largest file:

sudo find /var/log -type f -printf "%s %p\n" | sort -n | tail -1

from https://www.cyberciti.biz/faq/linux-find-largest-file-in-directory-recursively-using-find-du/

1 Like

The following near the top of the update file seems to work quite well:

# Find largest log file and remove
varlog_available=$(df | awk '$NF == "/var/log" { print $4 }')
if [ "$varlog_available" -lt "1024" ]; then
    largest_log_file=$(sudo find /var/log -type f -printf "%s\t%p\n" | sort -n | tail -1 | cut -f 2)
    sudo truncate -s 0 $largest_log_file
    echo "$largest_log_file truncated to make room for update log" 
fi
2 Likes