return to PRS Technologies website


du_dir.sh
#!/usr/bin/ksh ############################################################################### # # Module: du_dir.sh.sh # Author: Peter R. Schmidt # Description: Do a du (display disk space used), # but only show the main directories under the current directory. # # Change Log # # Date Name Description................. # 04/20/01 Peter R. Schmidt Start Program # ############################################################################### OUTPUT=du_dir.out TMPFILE=du_dir.tmp XDATE=`date +%D-%T` MACHINE=`uname -n` BOLD=`tput smso` NORM=`tput rmso` PWD=`pwd` ############################################################################### while true do echo echo "1 = Report in Megs" echo "2 = Report in Kbytes" echo "3 = Report in 512 byte blocks" echo "4 = Report in Bytes" echo "0 = Exit this program" echo echo "Enter reporting unit desired (0,1,2,3,4)" read OPTION1 case $OPTION1 in 0|1|2|3|4) break;; esac echo echo "Error - you must enter 0,1,2,3 or 4!" echo done case $OPTION1 in 0) echo "End requested by user"; exit;; 1) UNIT=M; UNITDESC=Mbytes;; 2) UNIT=K; UNITDESC=Kbytes;; 3) UNIT=P; UNITDESC=Blocks;; 4) UNIT=B; UNITDESC=Bytes;; esac while true do echo echo "Drill down to how many directory levels ? (1-9)" read LEVELS case $LEVELS in 1|2|3|4|5|6|7|8|9) break;; esac echo echo "Error - you must enter 1 - 9 !" echo done echo echo "Working..." echo #du | egrep -v "\.\/.*\/.*" > $TMPFILE du > $TMPFILE awk ' \ BEGIN { blocksize=2 } { if (NR == 1) { split (xdate,b,"-") udate=b[1] utime=b[2] printf "\n%s %s Unix Used Disk Space Report for %s\n", udate, utime, machine printf " (Numbers in %s) %s levels\n\n", unitdesc,levels } #------------ ON EVERY ROW ------------------------------------- num_slashes = split ($0,a,"/") num_slashes-- if (num_slashes <= levels) { print_line = "Y" } else { print_line = "N" } if (print_line == "Y") { indent_level = num_slashes - 1 indent_text = "" for (i = 2; i <= num_slashes; i++) indent_text = indent_text " " used_P = $1 dir_name = $2 dir_desc = dir_name if (dir_name == ".") { dir_desc = "Total in filesystem " pwd } used_K = used_P/blocksize used_M = used_K/1024 used_B = used_K*1024 used = 0 if (unit == "B") { used = used_B } if (unit == "P") { used = used_P } if (unit == "K") { used = used_K } if (unit == "M") { used = used_M } printf "%10d %-10s %s %s \n", used, unitdesc, indent_text, dir_desc if (num_slashes == 1) printf "\n" if (num_slashes == 1) { if (dir_name != ".") { tot_dir += used } } } } END { printf "%10d %-10s %s \n", tot_dir, unitdesc, "Total of all sub-directories" } ' levels=$LEVELS pwd=$PWD xdate=$XDATE machine=$MACHINE unit=$UNIT unitdesc=$UNITDESC $TMPFILE > $OUTPUT rm -f $TMPFILE pg $OUTPUT #echo #echo "Note: Output report is in $OUTPUT" rm -f $OUTPUT ###############################################################################