I'm trying to achieve the follwoinig with no luck.
Find the directories that are greater than 50GB in size and pick the owner of the directory as I would like to send an alert notification.
du -sh * | sort -rh
139G Dir_1
84G Dir_2
15G Dir_3
ls -l Dir_1
drwx------ 2 User1 Group1 4096 Aug 15 16:38 Dir_1
The script should resolve for Dir_1 and Dir_2 as the size is > 50GB and send a notification to User1 and User2 indicating that the directores have exceed the limit.
Apprecaiet any help.
---------- Post updated at 05:54 PM ---------- Previous update was at 04:48 PM ----------
I tried this.
#!/bin/ksh
dir_name=/apps/directory_name
cd $dir_name
du_cmd=`du -sh * | sort -rh`
for f in $du_cmd
do
echo $f
done
Output:
138G
Dir_1
76G
Dir_2
15G
Dir_3
1.7G
--------
I added bit more functionality
#!/bin/ksh
dir_name=/apps/directory_name
cd $dir_name
du_cmd=`du -sh * | sort -rh`
for f in $du_cmd
do
echo $f
echo `ls -ld $dir_name/$f | awk '{print$3}'`
done
Output:
156G
ls: cannot access /apps/directory_name/156G: No such file or directory
Dir_1
User_1
76G
ls: cannot access /apps/directory_name/76G: No such file or directory
Dir_2
User_2
15G
ls: cannot access /apps/directory_name/15G: No such file or directory
Dir_3
User_3
1.7G
ls: cannot access /apps/directory_name/1.7G: No such file or directory
Please help.