?
Solved

Monitor capacity of directory only

Posted on 2009-06-29
7
Medium Priority
?
350 Views
Last Modified: 2013-12-26
I am really stuck on finding a solution to a problem here.
I have a directory located at /lcl/app/prd/test1

I would like to be able to do the following...
Find the allowed space given to the directory test1.
Then find the capacity at which the directory test1 is at.

I was doing it this way...
space=`df -bhk /lcl/app/prd/test1| cut -d "y" -f1 | awk '{print$5}'`

However that seems to give me the capacity of the whole mount.  I only want a capacity of the directory test1, nothing before it should be included in the calculation.

I also thought of using the du command however I do not understand how to first look at the space given to the directory test1 and then how to compare that to the results of du since du does not give capacity.  I am not sure how to convert that into a capacity number which is exactly what I must have.

For example I would like to know if the directory test1 is at 80% capacity.
Again I do not want the whole filesystem... ONLY the directory test1.

Can anyone help me with this?  I am having a hard time figuring it out and I can not seem to find any answers on it.  Thank you in aadvance.

0
Comment
Question by:LarryRoberts
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
7 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24735471

Hi,
unless you were using quotas, there is no such thing as 'directory capacity'.
So you're on the right track when using 'df'.
Should there be quotas, however, you can check with
'repquota /lcl/app/prd/test1'
Note, however, that quotas exist only on a per-user basis.
wmp
0
 

Author Comment

by:LarryRoberts
ID: 24735581
The issue is I am not sure how to check for what the amount of storage that was given to that directory in the first place so that I can run the df return number against the amount of storage given number to see what percentage of that is full.  Or for that matter how to turn the value given from the df into a percentage.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24735600
df gives you a percentage!
Look at the column titled 'Use%' (or the like, depending on your Unix flavor).
 
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 2000 total points
ID: 24761407
... or do you want to know the percentage of space a directory occupies related to the whole filesystem?
If so, here is a script -
#!/bin/ksh
  [ $# -ne 1 ] && echo "Usage: $0 [/path/to/dir]" && exit
dir=$1
  dirsize=$(du -ks $dir | awk '{print $1}')
  DF=$(df -k $dir | grep -v Filesystem | awk '{print $2,$NF}')
set $DF
  fssize=$1
  mp=$2
dirpct=$(echo $dirsize $fssize | awk '{printf "%3.2f", $1 * 100 / $2}')
  echo "$dir occupies ${dirpct}% of the filesystem $mp"
exit
Save it under a scriptname of your choice, make it executable by issuing 'chmod +x scriptname', call it by 'scriptname /path/to/dir' (as root) and have fun!
wmp
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24837750
Don't worry about the #!/bin/ksh
The script will run under bash as well!
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question