|
How do I create a group-based disk usage script?
A reader writes:
"I've been reading your book Teach Yourself Unix in 24 Hours and learning a lot, but I'm stuck on a disk usage problem. Suppose there are 5 people (A, B, C, D, E) in our group
and they share the same directory called "group." The total capacity of this
directory is 100 GB. I'm looking for a program/command/script that can be
run to generate the following space usage update:
This is an interesting question, so let's dig into it and see what we can figure out...
That being the case, I'll first suggest that you put them into different home directories. You could even have those directories under the shared directory, as in /home/group/A and /home/group/B, etc. That'd make things easy to track. Failing that, it's still quite possible to ascertain disk usage on a per userID basis by using the find command. For example, consider using find / -user A -type f -print, which would generate a list of all files owned by user A across the entire file system, or, better, using the slightly more complex find / -user A -type f -exec ls -ld \{\} \; which generates output similar to: -rw------- 1 taylor staff 21508 1 Nov 23:20 ./.DS_Store -rw-r--r-- 1 taylor staff 0 8 Apr 2004 ./.localized -rwxr-xr-x 1 taylor staff 950272 29 May 2003 ./021022_0801.bin -rwxr-xr-x 1 taylor staff 69 17 Sep 2003 ./021022_0801.cue With that information, you should be able to create a brief awk script that sums up all the numbers in column #5, divides by 1024 and presents the final disk space used by each user in the group in Kb (or divide by 1024*1024 and get Mb). To go from that to calculating what % of the total alloted space for the group each person is using should be straightforward. Hope that helps you!
Categorized:
Shell Script Programming
(Article 3753,
Written by Dave Taylor)
Tagged: Previous: How do I map XX.com to www.XX.com in Apache? Next: How do I dual boot Ubuntu Linux & Mac OS X? Subscribe!
Hi Dave, I want the unix shell script to check the disk usage at each mount point and if the space is less than 2GB(at any mount point) it should send a mail to my email id. In this, the values will be in GB or MB sometimes, so I want the script to exactly compare the value 2GB. Hoping for your answer soon, With Regards & thanks I would love to see a version of this script, and for that matter the disk monitoring script from Dave's "wicked cool scripts" book, that doesn't use /etc/passwd, but rather copes with a multitude of LDAP users. Posted by: Deanypop at November 28, 2006 5:48 PMI am putting this command on unix but not getting the result - find / -user A -type f -print Posted by: imran at February 22, 2007 8:35 AMAs always, Imran, check the man page for your version of Unix to ensure that the flags work as you expect. For example, -user might require a user ID number, not name... Posted by: Dave Taylor at February 27, 2007 11:33 PMhow to find disk usage of a particular directory? Posted by: vinod parmar at April 16, 2008 12:14 AMDisk usage for a 'directory': du -s directory I have something to say, now that you mention it, but ...
I do have a comment, now that you mention it!
|
Recommended
Recent Entries
Search
I Need Help!
Apple iPad Help
Articles and Reviews Auctions and Online Shopping Blogs and RSS Feeds Building Web Site Traffic Business and Management CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above Facebook Help Google Plus Help HTML and CSS Industry News and Trade Shows iPhone and Cell Phone Help iPod, Sony PSP and MP3 Player Help Mac OS X Help Pay Per Click (PPC) Advertising Search Engine Optimization (SEO) Shell Script Programming Tech Support Video Help The Writing Business Twitter, LinkedIn and Social Network Help Unix and Linux Help Video Game Tips and Help Windows PC Help WordPress Help |