Sponsored Content
Top Forums Shell Programming and Scripting Folder growth in mount points Post 302655411 by clx on Wednesday 13th of June 2012 06:49:10 AM
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.
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
mvdir(1M)																 mvdir(1M)

NAME
mvdir - move a directory SYNOPSIS
dir newdir DESCRIPTION
moves one directory tree into another existing directory (within the same file system), or renames a directory without moving it. dir must be an existing directory. If newdir does not exist but the directory that would contain it does, dir is moved and/or renamed to newdir. Otherwise, newdir must be an existing directory not already containing an entry with the same name as the last pathname component of dir. In this case, dir is moved and becomes a subdirectory of newdir. The last pathname component of dir is used as the name for the moved directory. refuses to move dir if the path specified by newdir would be a descendent directory of the path specified by dir. Such cases are not allowed because cyclic sub-trees would be created as in the case, for example, of which is prohibited. does not allow directory to be moved. Only users who have appropriate privileges can use EXTERNAL INFLUENCES
International Code Set Support Single- and multi-byte character code sets are supported. AUTHOR
was developed by OSF and HP. SEE ALSO
cp(1), mkdir(1), mv(1). STANDARDS CONFORMANCE
mvdir(1M)
All times are GMT -4. The time now is 04:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy