Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script for Checking Disk usage daily... 2

Status
Not open for further replies.

bchacon

IS-IT--Management
Sep 3, 2001
4
US
Ok... I know this sounds basic from the "subject" line, but I am trying to do something slightly more complicated. I want to be able to have a script that will check several directories as to how much disk space each is using and then pipe or redirect this information to a template that will format the information so as appropriate to be read by the common person. Does this make sense?? It's basically a du -k command for several directories that I designate. My boss wants it in a format that can be read on a weekly basis. Each directory is allocated a certain amount of space. When the client using that directory goes over the allocated storage, we would like to bill for that overage. I just need a script that will give me that report. Anyone?? I would very much appreciate the help. I'm not asking for the entire script... or maybe I am. Basically, any help would be appreciated. Very appreciated!

Thanks.
 
Here's a suggestion to get you started. Lets say you have a file called dirlist which contains the full paths to all the directories which you want to monitor, one entry per line. This script will show the total usage (in 1024 byte units) for each directory.
Code:
for d in `cat dirlist`
do
  du -k $d|tail -1
done
Is this the sort of thing you're after?

Greg.
 
Thanks so much for the quick response. Carlos, BigAdmin was my first stop. Although, I thank you for your help.

Greg, your answer provided me with an angle I had not thought of. Let's say I used your script and then insterted it into a cron. If I wanted the output to be emailed to me, what additional lines would I have to enter into your script to allow for that.
 
The simplest way is
Code:
for d in `cat dirlist`
do
  du -k $d|tail -1
done | mail username
Regards,

Greg.
 
I use the following in a script and you could have cron run the script as often as you need. I am only looking at filesystems over 80% full. you could remove that last bit about the 80% if you needed all filesystems.
A sample of the out put is below it.


df |awk '{ printf "%-15s %s\n" , $7 , $4 }'|sort -n -k 2,2|egrep "Mount|[8-9][0-9]%|100%"


Sample output:



Mounted %Used
/scratch 85%
/ 86%
/quipulogs 87%
/home 92%
/usr 94%
/usr1 95%


Hope this is useful
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top