Hey guys,
I want to mention that I'm still a beginner at this so bear with me
I made a small script that will check the users and if the size is larger than, let's say 204800, it will print the user and then send an email with the report.
Everything works except the fact that the script prints all the users, not only the one's having the value larger than 204800
This is the script, any suggestions are welcome:
Code:
#! /bin/bash
#finding all users, checking folder size and sorting
/usr/bin/find /home -printf "%u %s\n" | /usr/bin/awk '{user[$1]+=$2}; END { if (user[i] -gt 204800) for( i in user) print i " " user[i]}' | /bin/sort -rn +1 -2 > /root/disk-usage.txt;
#cheking if there is something in disk-usage.txt
if ls /root/ | grep -q "disk-usage.txt"
then
# send email containing the output of the file
/bin/cat /root/disk-usage.txt | mail -s "Disk Usage Report" my@email.com
fi;
#delete txt file
rm -rf /root/disk-usage.txt