Folder growth in mount points


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Folder growth in mount points
# 1  
Old 06-13-2012
Folder growth in mount points

I have a file server that has a pretty large folder tree. There's a shared folder, under that are 5 departmental folders. Nested inside of those are thousands of subfolders and files.

I would like to be able to trace growth of those 5 departmental folders. There are certain particular sub-sub-sub folders I'd also like to keep an eye on. This is so that, if I suddenly see my disk utilization % skyrocket, I can have a clue as to what folder this growth happened in, so I can drill down and discover whodunnit.

Any suggestions how to track the growth of each folder inside a mount point?Smilie
# 2  
Old 06-13-2012
I use this little perl script to trace the usage of directories (including sub-dirs).
This provides output in human readable form (mb, gb etc)

Code:
#!/bin/perl
use File::Find;
# Determine wether argument is given or not
# -----------------------------------------
if (@ARGV) {
@dirm = @ARGV;
foreach $dirm(@dirm) {
if ($dirm eq "\." ) {
$dirm = `pwd`;
$dirm =~ s/\n//g;
}
$dirm =~ s/\/$//g;
push(@directory, $dirm);
}
}
else {
usage();
}
# -----------------------------------------

# Define global vars and hashes
# -----------------------------------------
%seen = ();
$total = ();
$nr = 0;
$mbnr = 0;
# -----------------------------------------

# Searching starting at your given directory
foreach $directory (@directory) {
finddepth(\&wanted, $directory);
}


# If this is dir is unique, start getting total disk usage inclusive sub-dirs
# ---------------------------------------------------------------------------
sub wanted {
$dir = "$File::Find::dir";

unless ($seen{$dir}++) {
next if ( $dir =~ lost+found );
next if ( $dir eq $directory );
$dm=`du -ks $dir 2>/dev/null`;
($kb, $path) = split /\s+/, $dm ;
$mb = int( $kb / 1024 );

$output{$path} = $mb;

}
}
# -----------------------------------------

# Determine most characters of path and store it in $nr
# -----------------------------------------
@long = keys %output;
foreach $item(@long) {
if ( $nr < length($item)) {
$nr = length($item);
}
}
# -----------------------------------------


# Determine most characters of size and store it in $mbnr
# -----------------------------------------
@long = values %output;
foreach $item(@long) {
if ( $mbnr < length($item)) {
$mbnr = length($item);
}
}
# -----------------------------------------

# Add a space as long as the the current path is smaller then the longest one.
# -----------------------------------------
print "\n\n\n";
while (($key, $value) = each %output) {
$numb = ( $nr - length($key) );
$mbnumb = ( $mbnr - length($value) );
$dd = " Directory $key has";
while ( $numb > 0 ) {
$dd = $dd . " ";
$numb--;
}
while ( $mbnumb > 0 ) {
$dd = $dd . " ";
$mbnumb--;
}
push(@newarray, "$dd $value Mb\n");
}
# -----------------------------------------

# Print total directory size
# -----------------------------------------
foreach $line(sort(@newarray)) {
print $line;
}

print "\n\n";

foreach $directory(@directory) {
$total=`du -ks $directory 2>/dev/null`;
($total_size, $useless) = split /\s+/, $total;
$total_size_mb = int( $total_size / 1024 );
print "Total usage of $directory is $total_size_mb Mb\n";
}
print "\n\n";
# -----------------------------------------


sub usage() {
print "\ndirinfo.pl: Error incorrect usage \n\n";
print "Usage: /usr/local/bin/dirinfo.pl <directory> \n";
print "\t <directory> Is directory start point to check \n\n\n";
exit 1;
}


To use, Just pass the path of the main directory as the argument.
Code:
./space.pl /path/to/departmental_folder

This would print the info on STDOUT. Use redirection if you want further processing the result as per your need e.g sorting ascending based on size which is simple with shell tools like sed/awk.

Hope it helps.
# 3  
Old 06-13-2012
is it possible using shell scripts.
# 4  
Old 06-13-2012
Do you want the size for each sub-dir separately?

If not, du -sh <DIR> should give the size in human readable form.

what is your OS? "-h" seems to work on Linux and Solaris (for other OS, I have only tested it on HP-UX on which it doesn't work) where you can use du -sk <DIR> which would display the size in kbs
# 5  
Old 06-13-2012
i want the size of each sub-directory.Also the %growth of each sub directory and the main directory.

---------- Post updated at 04:40 PM ---------- Previous update was at 04:38 PM ----------

Basically i want to prepare a report so that i can mointor the utilization of mount point.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Types of mount points

Hi, What are the types of mount points available in Linux machine and how to find what type of mount point is configured in my linux machine? Is mount point otherwise called as file system or do they have different meaning ? Regards, Maddy (4 Replies)
Discussion started by: Maddy123
4 Replies

2. Red Hat

Mount Points? How?

Hi folks, I have been asked to performed the following: Add the following new moint points systemA:/avp and SystemB:/usr/sap/trans to be the new linux server ZZZ How can I add those mount points and how those mount points can become another linuz server?:wall::wall::wall: (2 Replies)
Discussion started by: 300zxmuro
2 Replies

3. UNIX for Advanced & Expert Users

mount points

hi, I believe a mount point does not have to be a physical disk, but rather a logical one? Is this correct? if so, how can I find out if my mount points are on different physical disks? thanks (9 Replies)
Discussion started by: JamesByars
9 Replies

4. UNIX for Dummies Questions & Answers

mount points are already mounted

Hi, I have some issue with the mounting/unmounting on my sun solaris box. Actually their is one script that mount the file system take the backup of databases and unmount the file system.Last week this script failed to mount the file system with the below error message: + echo fs_check.sh:... (1 Reply)
Discussion started by: biju.mp
1 Replies

5. HP-UX

Cannot unmount mount points??

When taking a snap, I have a script that stops any active snap. When running the script, I'm getting a message that u02 and u04 are already mounted. How can I find out what process(es) is/are latching on the these mount points? Thank you for your time. (1 Reply)
Discussion started by: genzbeat
1 Replies

6. Solaris

Mount points of available Vxvm disks

I have situation where I want to know about all the vxvm mount points information on my solaris box, because after rebooting the server the few mount points are not mounted automatically because they where not copied in /etc/vfstab. So please help me out on the same.:( (0 Replies)
Discussion started by: nimish_mehta
0 Replies

7. UNIX for Dummies Questions & Answers

NFS Mount Points

Hi Solaris 10 On server A, there is a directory called data with 10 files. This data directory has a further 3 subdirectories, gl, pay, contract (for example) On server B, I want to see the server A data directory commands used: on server A, share -F nfs -o ro -d "<description">... (1 Reply)
Discussion started by: davidra
1 Replies

8. UNIX for Dummies Questions & Answers

Mount Points at reboot

How do I make a mount point reconnect at boot without editing /etc/fstab? Is there an option (or switch) to make this persistent when issuing the mount command from a client? (1 Reply)
Discussion started by: AIXdumb455
1 Replies

9. UNIX for Dummies Questions & Answers

tar using mount points

hi i tried to tar a directory in my server but it show ensufficient space. therefore i tried to save it to a mount point using tar /mountpoint/newfilename file2btar but it gives me permission denied. i am using the root account to do this. is it possible to tar files and put it to mounted... (3 Replies)
Discussion started by: legato
3 Replies

10. UNIX for Advanced & Expert Users

mount points

sometimes in Solaris 8 when I go to mount filesystems using either the mount command or by editing the /etc/vfstab, i get a nice little error message saying the the number of allowable mount points has been exceeded. I have read man pages until I am blue in the face and no where can I find what the... (3 Replies)
Discussion started by: manderson19
3 Replies
Login or Register to Ask a Question