Link to home
Start Free TrialLog in
Avatar of rdashokraj
rdashokraj

asked on

Script for comparing 2 files for tracing the disk usage.

Hello Experts,

Need your help. I have a requirement to create one bash script for analyzing the disk usage. Let me detail here. We have a NetApp filer and it hosts many users’ home folders. The problem we face is that the disk usage is becoming full always. As the filer consists of too many folders, its very difficult for us to trace out the disk usage correctly. The procedure we follow now is to take a folder-wise screen-shot in a file and compare it to the previous screen-shot, by which we can find the difference in the folder size and trace out the folder whose size increased recently. Screen-shot in the sense, being in root /, we run this command: #du –sk * > filename.<date>.  E.g: #du –sk * > diskusage.04Oct06

This file will contain the disk usage detail of all the folders in the root folder. To list all the folders based on size, we use the following command:

#cat diskusage.04Oct06|sort –n.

So when we want to find which folder size has increased recently, we will manually do a comparison between the current file and the previous week file. But this process is tedious, as we have to check several folders. That’s the reason I like to write a script for this (But I don't know much about scripting).

Let me tell you in simple terms about my requirements:

We have two files (say diskusage.04Oct06 and diskusage.28Sep06) which contains the folder-size details of a directory (say /). Now we need a script which compares these two files and get us a output of difference in disk usage of the respective folder.

The logic can work like this. First it should compare the strings (filenames) in both the files, if it matches, calculate the difference (filesize value) and display the result. Incase if both the strings aren’t matching then it should discard it.  Hope you got it.  Can anyone work on this and get me the script?

 
Sample disk usage screenshot file:


bash-2.05# cat dus.04-26-06|sort -n

8       AR
2196    blfs
77160   hris_project
360032  hr
502520  speedy
3280756 purch_rep
3372096 micropower
3434676 rpq_data
3530012 document
4082684 Legal_Dept
5077992 netadmin
7461988 Oracle_11i
8872748 gollum
11508516        Treasury_NT
16117436        terminated
26566756        home1unix
28623272        FA
35648704        marcom
44091864        misadmin
56374524        unix
bash-2.05#

Thanks,
Ashok

PS:  IF YOU HAVE ANY OTHER ALTERNATIVE SCRIPT ALSO, FINE WITH ME. All I want is to trace the disk usage.
Avatar of chris_calabrese
chris_calabrese

Sounds like you really want Quotas. See http://www.netapp.com/library/tr/3425.pdf
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial