###########################################
# 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=<STDIN>; #parent of the directories to get sizes of
chomp($path);
print "\n\nEnter the minimum in megs:\n\n\n";
$minsize=<STDIN>; #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 (M
+egs)\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;
In reply to audit.pl
by Arcanum
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.