|
|
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...
First off, you say that the users are sharing a particular directory, so I'm going to assume you mean that they all have the same home directory on the system, but have discrete entries in the password file (that is, different user IDs). This would be shown if you did an ls -l and saw files owned by each of the users in the same home directory.
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!
Related Shell Script Programming articles:
✔ Secretly capture screenshots on my Mac?
When I used to work on a Linux system, there was a utility we had that would let me take screen captures every...
✔ Parsing "id" strings in a Shell Script?Hello Dave. I need a Bash shell script that creates a directories with the group names automatically when user logs in to the...
✔ Copy and Paste from the Mac OS X Command Line?I am constantly running commands in Terminal.app on my MacBook and then copying and pasting the results into email messages or documents. Yes,...
✔ Script to test line lengths for Twitter compatibility?I've been tasked with writing a series of tweets for a Black Friday marketing campaign and am finding it a bit tricky because...
✔ Shell script to convert lowercase to title case?As part of a project I'm working on, I find myself deep in a Linux shell script, needing to have a subroutine that...
Let's stay in touch!
Sign up for my weekly AskDaveTaylor Newsletter and you'll receive even more tech and gadget help
right to your inbox, along with exclusive news and industry updates. It's good stuff. I promise!
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? Reader Comments To Date: 6Deanypop said, on November 28, 2006 5:48 PM:
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. imran said, on February 22, 2007 8:35 AM:
I am putting this command on unix but not getting the result - find / -user A -type f -print Dave Taylor said, on February 27, 2007 11:33 PM:
As 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... vinod parmar said, on April 16, 2008 12:14 AM:
how to find disk usage of a particular directory? Antriksh Pany said, on March 20, 2010 11:49 PM:
Disk usage for a 'directory': du -s directory
I do have a comment, now that you mention it!Check This Out Too... |
Recent Entries
Look for Answers
Recommended
All Our Categories
Apple iPad Help
Articles and Reviews Auctions and Online Shopping Blogs and Blogging Building Web Site Traffic Business and Management Computer and Internet Basics d) None of the Above Facebook Help Google Gmail Help Google Plus Help HTML, JavaScript and Web Site Programming Industry News and Trade Shows iPhone and Cell Phone Help iPod, Sony PSP and MP3 Player Help Kindle Fire Help Mac OS X Help Pay Per Click (PPC) Advertising Pinterest Help 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 Find Me on Google+ ADT on G+ |
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
Subramanyam Karanam