Below is the shell script to find out top 10 users utilizing work directory. This script tested in Solaris and may or may not work in *.nix versions.
## Script to find Top users in Work Directory (/work)
echo " \n Top 10 Work directory and Memory in GB " > Temp_Mail.txt
echo " \n Size Directory_Name \n" >> Temp_Mail.txt
du -sh /work/SAS*|/usr/xpg4/bin/grep -E 'T'|grep -v 'K'|grep -v 'M'|sort -nr|head -10 >> Temp_Mail.txt
du -sh /work/SAS*|/usr/xpg4/bin/grep -E 'G'|sort -nr|head -10 >> Temp_Mail.txt
du -sh /work/SAS*|/usr/xpg4/bin/grep -E 'T'|grep -v 'K'|grep -v 'M'|sort -nr|head -10|cut -c 13-39 > Temp_User.txt
du -sh /work/SAS*|/usr/xpg4/bin/grep -E 'G'|sort -nr|head -10|cut -c 13-39 >> Temp_User.txt
var1=`sed -n '1p' Temp_User.txt`
var2=`sed -n '2p' Temp_User.txt`
var3=`sed -n '3p' Temp_User.txt`
var4=`sed -n '4p' Temp_User.txt`
var5=`sed -n '5p' Temp_User.txt`
var6=`sed -n '6p' Temp_User.txt`
var7=`sed -n '7p' Temp_User.txt`
var8=`sed -n '8p' Temp_User.txt`
var9=`sed -n '9p' Temp_User.txt`
var10=`sed -n '10p' Temp_User.txt`
echo "\n Top 10 User List with SAS Work Directory \n" >> Temp_Mail.txt
ls -ldrt /work/$var1 >> Temp_Mail.txt
ls -ldrt /work/$var2 >> Temp_Mail.txt
ls -ldrt /work/$var3 >> Temp_Mail.txt
ls -ldrt /work/$var4 >> Temp_Mail.txt
ls -ldrt /work/$var5 >> Temp_Mail.txt
ls -ldrt /work/$var6 >> Temp_Mail.txt
ls -ldrt /work/$var7 >> Temp_Mail.txt
ls -ldrt /work/$var8 >> Temp_Mail.txt
ls -ldrt /work/$var9 >> Temp_Mail.txt
ls -ldrt /work/$var10 >> Temp_Mail.txt
echo "\n Regards \nSAS Admin" >> Temp_Mail.txt
mailx -s "Work Directory Memory Usage on `date +%d-%m-%Y-%T`" -r SASAdmin@sas.com SASAdmin@sas.com < Temp_Mail.txt
## Script to find Top users in Work Directory (/work)
echo " \n Top 10 Work directory and Memory in GB " > Temp_Mail.txt
echo " \n Size Directory_Name \n" >> Temp_Mail.txt
du -sh /work/SAS*|/usr/xpg4/bin/grep -E 'T'|grep -v 'K'|grep -v 'M'|sort -nr|head -10 >> Temp_Mail.txt
du -sh /work/SAS*|/usr/xpg4/bin/grep -E 'G'|sort -nr|head -10 >> Temp_Mail.txt
du -sh /work/SAS*|/usr/xpg4/bin/grep -E 'T'|grep -v 'K'|grep -v 'M'|sort -nr|head -10|cut -c 13-39 > Temp_User.txt
du -sh /work/SAS*|/usr/xpg4/bin/grep -E 'G'|sort -nr|head -10|cut -c 13-39 >> Temp_User.txt
var1=`sed -n '1p' Temp_User.txt`
var2=`sed -n '2p' Temp_User.txt`
var3=`sed -n '3p' Temp_User.txt`
var4=`sed -n '4p' Temp_User.txt`
var5=`sed -n '5p' Temp_User.txt`
var6=`sed -n '6p' Temp_User.txt`
var7=`sed -n '7p' Temp_User.txt`
var8=`sed -n '8p' Temp_User.txt`
var9=`sed -n '9p' Temp_User.txt`
var10=`sed -n '10p' Temp_User.txt`
echo "\n Top 10 User List with SAS Work Directory \n" >> Temp_Mail.txt
ls -ldrt /work/$var1 >> Temp_Mail.txt
ls -ldrt /work/$var2 >> Temp_Mail.txt
ls -ldrt /work/$var3 >> Temp_Mail.txt
ls -ldrt /work/$var4 >> Temp_Mail.txt
ls -ldrt /work/$var5 >> Temp_Mail.txt
ls -ldrt /work/$var6 >> Temp_Mail.txt
ls -ldrt /work/$var7 >> Temp_Mail.txt
ls -ldrt /work/$var8 >> Temp_Mail.txt
ls -ldrt /work/$var9 >> Temp_Mail.txt
ls -ldrt /work/$var10 >> Temp_Mail.txt
echo "\n Regards \nSAS Admin" >> Temp_Mail.txt
mailx -s "Work Directory Memory Usage on `date +%d-%m-%Y-%T`" -r SASAdmin@sas.com SASAdmin@sas.com < Temp_Mail.txt
Assumptions:
You will receive mail if you server is configured with MailX program. This program doesn't delete any files or directory.
Comments
Post a Comment