Skip to content

Instantly share code, notes, and snippets.

@huynhbaoan
Last active April 30, 2023 08:20
Show Gist options
  • Save huynhbaoan/b7388ed63409656c1219a0fb6e7a5c66 to your computer and use it in GitHub Desktop.
Save huynhbaoan/b7388ed63409656c1219a0fb6e7a5c66 to your computer and use it in GitHub Desktop.
Bash shell snippet for daily use
# Generate du command to check disk
# Ignore all the mount points nfs4. Modify the "df -t nfs4" as you want
# Run with lowest CPU priority and lowest diskio priority
# extract the content from the last column and store it in an array
IFS=$'\n' read -d '' -ra MOUNT_POINTS <<< "$(df -h -t nfs4 | awk '{print $NF}')"
# construct the new du command with the excluded mount points
DU_COMMAND="nice -n 19 ionice -c 3 du -shxc /* --exclude=/proc"
for mount_point in "${MOUNT_POINTS[@]}"; do
DU_COMMAND+=" --exclude=$mount_point"
done
# echo the du command, excluding the mount points and /proc/, and sorting the output by size
echo "$DU_COMMAND | sort -h"
# Find delete log file older than 10 days
find /var/log/ -type f -mtime +10 -print -delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment