check home disk usage script

# cat ./check_quotas.sh

!/bin/bash

day_max_limit=30 #int
home_dir_size_limit_bytes=1000000 #int
file_size_mb=10 #int

for host in ihop1; do
while read LINE; do
username=$(echo “$LINE” | cut -f1 -d”:”)
home_path=$(echo “$LINE” | cut -f6 -d”:” | egrep ‘(home|homes)’)
if [[ -e $home_path ]]; then
home_dir_size_bytes=$(du -s ${home_path} | cut -d ‘/’ -f 1 | tr -d [[:space:]] )
home_dir_size_mb=$(expr “$(($home_dir_size_bytes/1024))”)
if [[ “$home_dir_size_bytes” -gt “$home_dir_size_limit_bytes” ]]; then
cmd=$(find $home_path -ctime +${day_max_limit} -size +${file_size_mb}M -exec du -sh {} \;)
if [[ ! -z $cmd ]]; then
echo -e “Hi $username,\n\nYou’re home directory $home_path on $host is now ${home_dir_size_mb}M. This server is intended for temporary storage and will be purge every 30 days.\n”
#echo “” #echo $username@$host:$home_path
for file in $cmd; do
echo $file;
done
echo “”
fi
fi
fi
done < /etc/passwd
done

Leave a Reply