########################################### # Audit script to get a good estimate # # of total disk space used by each client # ########################################### print "\n\nEnter the path of the directory to check: (i.e. e:\\\\web, note the double-backslashes - these are necessary)\n\n\n"; $path=; #parent of the directories to get sizes of chomp($path); print "\n\nEnter the minimum in megs:\n\n\n"; $minsize=; #disk space usage to check against print "\n\n\n"; chomp($minsize); $minsize=$minsize*1048576; #converted to bytes $sdbpath1="m:/"; #SQL Database paths $sdbpath2="n:/"; $adbpath="d:/dbase"; #Access Database path chdir($path); @files=`dir /b`; #uses the 'bare' switch of the 'dir' command #to get a list of directories to size open (OUTFILE, ">c:/audit.txt"); print OUTFILE "Folder\t\t\tLogs (Megs)\t\tDatabases (Megs)\t\tTotal (Megs)\n\n"; foreach $file (@files){ chomp($file); ############################################## # This loop recursively sizes one directory # # at a time from the list in @files, using # # the DOS command 'dir /s'. # # It then uses some array manipulation # # and substitution to get the total in bytes # ############################################## if (-d $file){ @temparray=`dir /s "$file"`; pop(@temparray); $tempout=pop(@temparray); $tempout =~ s/ //g; $tempout =~ s/,//g; $tempout =~ s/bytes//; $tempout =~ s/.{0,8}File\(s\)//; chdir($file); ######################################### # After changing to the client's # # directory, use 'dir /s' again # # to get the size of the logs directory # ######################################### @logarray=`dir /s Logs`; pop(@logarray); $logtemp=pop(@logarray); $logtemp =~ s/ //g; $logtemp =~ s/,//g; $logtemp =~ s/bytes//; $logtemp =~ s/.{0,8}File\(s\)//; chdir($sdbpath1); ################################### # Same story for the SQL database # # directories # ################################### if (-d $file){ @sdbarray1=`dir /s "$file"`; pop(@sdbarray1); $sdbtemp1=pop(@sdbarray1); $sdbtemp1 =~ s/ //g; $sdbtemp1 =~ s/,//g; $sdbtemp1 =~ s/bytes//; $sdbtemp1 =~ s/.{0,8}File\(s\)//; } else{ $sdbtemp1=0; } chdir($sdbpath2); if (-d $file){ @sdbarray2=`dir /s "$file"`; pop(@sdbarray2); $sdbtemp2=pop(@sdbarray2); $sdbtemp2 =~ s/ //g; $sdbtemp2 =~ s/,//g; $sdbtemp2 =~ s/bytes//; $sdbtemp2 =~ s/.{0,8}File\(s\)//; } else{ $sdbtemp2=0; } chdir($adbpath); ############################### # ...And the Access Databases # ############################### if (-d $file){ @adbarray=`dir /s "$file"`; pop(@adbarray); $adbtemp=pop(@adbarray); $adbtemp =~ s/ //g; $adbtemp =~ s/,//g; $adbtemp =~ s/bytes//; $adbtemp =~ s/.{0,8}File\(s\)//; } else{ $adbtemp=0; } $dbtemp=$sdbtemp1+$sdbtemp2+$adbtemp; #add database totals $tempout=$tempout-$logtemp; #subtract uncompressed log #size from total $logtemp=$logtemp/4; #guesstimate for compressed #log files $tempout=$tempout+$logtemp; #add compressed log size #back to total $tempout=$tempout+$dbtemp; #add database size if ($tempout > $minsize){ $logtemp=$logtemp/1048576; #convert to megabytes $tempout=$tempout/1048576; $dbtemp=$dbtemp/1048576; printf OUTFILE ("$file\t\t%.2f\t\t\t%.2f\t\t\t\t%.2f\n", $logtemp, $dbtemp, $tempout); } chdir($path); } } close OUTFILE;