Guest User

Untitled

a guest
Dec 9th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. # -disk_check.csh takes dir name as a mandatory argument and an options <num> or -verbose as a second argument.
  2. # Ex1: disk_check <dir_name> - Reports out the disk usage per user and the total disk consumption
  3. # Ex2: disk_check <dir_name> -verbose -Along with the above, it also lists all files by size in the given directory
  4. # Ex3: disk_check <dir_name> -<num> -Similar to Ex2, But here it reports out the top <num> files by size in the given directory
  5.  
  6.  
  7. if ($#argv == 0) then
  8. echo " Error : Dir path missing"
  9. echo " Syntax : disk_check <dir-name> <verbose>"
  10. echo " verbose gives a list of all files per individual sorted by size"
  11. exit 0
  12. endif
  13.  
  14. set cwd = $argv[1]
  15. if ($cwd =~ "-help") then
  16. echo " Error : Dir path missing"
  17. echo " Syntax : disk_check <dir-name> <-verbose>"
  18. echo " -verbose gives a list of all files per individual sorted by size"
  19. exit 0
  20. endif
  21.  
  22. if ($#argv > 1) then
  23. set opt = $argv[2]
  24. #echo "opt : $opt"
  25. endif
  26.  
  27. if ( -d $cwd ) then
  28.  
  29. set ava = `df -h $cwd | tail -1 | awk '{print $1'}`
  30. set tot = `df -h $cwd | tail -1 | awk '{print $2'}`
  31. set ad = `df -h $cwd | tail -1 | awk '{print $3'}`
  32. set pcu = `df -h $cwd | tail -1 | awk '{print $4'}`
  33.  
  34. echo ""
  35. echo "Summary for dir ${cwd}: $tot Used (${pcu})"
  36. echo "-----------------------------------------------------------------------------"
  37. echo " Total Volume $ava"
  38. echo " Available on disk $ad "
  39. echo " Percentage used $pcu"
  40. echo ""
  41. echo "Summary by User:"
  42. printf "%sUser%15sSize%10sCountn" ""
  43. echo "---------------------------------------------"
  44.  
  45. **time find $cwd -type f -printf "%u %sn" | awk '{user[$1]+=$2;count[$1]++}; END{ for( i in user) printf "%s%-13s%5s%-0.2f%s%5s%7sn","", i, "", user[i]/1024**3,"GB", "", count[i]}'| sort -nk2 -r**
  46.  
  47.  
  48. if ($#argv > 1) then
  49. if ($opt =~ "-verbose") then
  50. echo "nDetail, Sorted by size"
  51. printf " User%15sFile%15sSizen" ""
  52. echo "---------------------------------------------------"
  53. find $cwd -type f -not -path '*/.*' -printf "%-13u | %-50p | %-10s n" | sort -nk5 -r
  54. endif
Add Comment
Please, Sign In to add comment