
How do I customize a script from "Wicked Cool Shell Scripts"?Regarding script #41 (calculating available disk space), out of your book Wicked Cool Shell Scripts, I am unclear how I can have this script calculate the free space on one specific drive, namely /Volumes/Documents HD in my case. I'd also love to know how I can automatically email the results of this same script, say every 24 hours. If you could kindly point me in the right direction, I'm sure I could figure out the rest! This is a fairly straightforward script you've asked about, so this will be an easy explanation. The most important line in the diskspace script is: df -k | awk -f $tempfile
Let's just run a quick df -k so you can see the output in question: $ df -k Filesystem 1K-blocks Used Avail Capacity Mounted on /dev/disk0s9 156277884 63170972 92850912 40% / devfs 101 101 0 100% /dev fdesc 1 1 0 100% /dev <volfs> 512 512 0 100% /.vol /dev/disk1s3 156159792 138235824 17923968 89% /Volumes/X2 automount -nsl [206] 0 0 0 100% /Network automount -fstab [214] 0 0 0 100% /automount/Servers automount -static [214] 0 0 0 100% /automount/static The important thing to see here is that I have one non-root drive, /Volumes/X2, and that it shows up in the list exactly in that format. This means that you can weed out other drives by using a call to grep. I'd tally up all drives on /Volume by doing this: df -k | grep /Volumes | awk -f $tempfile
You could be even more specific, by using your hard disk name too: df -k | grep /Volumes/Documents\ HD | awk -f $tempfile
Either way, changing that one line should accomplish what you seek. In terms of automatically emailing the results every 24 hours, that's a job for crontab. Start with man crontab and you'll find that it's not too terribly hard to figure out. If you would like to learn more about crontab and related administrative features of Unix, I suggest my brand new fourth edition of Teach Yourself Unix in 24 Hours.
Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Simpy.
Categorized:
Shell Script Programming
(Article 4132)
Tagged: Previous: Why was Elvis Presley called the King of Rock 'n Roll? Next: One site, lots of subdomains, or multiple sites? Subscribe!
Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.
Rather amazingly, there are no comments on this article yet.
I have a lot to say, but ...
I do have a comment, now that you mention it!
|
Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.
Help!
Subscribe to
Ask Dave Taylor!
Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.
Articles and Reviews
Auctions and Online Shopping Blogs and RSS Feeds Building Web site traffic Business and Management Cell Phones and Mobile Phones CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above HTML and CSS Mac OS X Help MySpace, Facebook, Twitter and Social Network Help Pay Per Click (PPC) Search Engine Optimization Shell Script Programming Sony PSP, MP3 Players, Etc. The Writing Business Unix and Linux Help Video Game Tips and Help Windows Help
Recent Entries
Join the List!
Book Links
|