
Subscribe to
Computerworld
|
April 05, 2004 (Computerworld) -- The following is excerpted from Wicked Cool Shell Scripts, published by No Starch Press, all rights reserved.
Wicked Cool Shell Scripts is "about making Unix a friendlier, more powerful, and more personal computing environment by exploiting the remarkable power and capabilities of the shell," says author Dave Taylor. "Without writing a single line of C or C++, without invoking a single compiler and loader, and without having to take any classes in program design and methodology, you [can] write dozens of wicked cool shell scripts, ranging from an interactive calculator to a set of scripts that make analyzing Apache log files a breeze."
The script below helps system administrators track down users who are exceeding their system storage limits, and will also automatically notify those users that they've maxed out their disk allocation.
Most system administrators seek the easiest way to solve a problem, and the easiest way to manage disk quotas is to extend the fquota script, Script #39, to include the ability to e-mail warnings directly to users who are consuming too much space.
The Code
#!/bin/sh
# diskhogs - Disk quota analysis tool for Unix; assumes all user
# accounts are >= UID 100. E-mails message to each violating user
# and reports a summary to the screen.
MAXDISKUSAGE=20
violators="/tmp/diskhogs0.$$"
trap "/bin/rm -f $violators" 0
for name in $(cut -d: -f1,3 /etc/passwd | awk -F: '$2 > 99 { print $1 }')
do
echo -n "$name "
# You might need to modify the following list of directories to match
# the layout of your disk. Most likely change: /Users to /home
find / /usr /var /Users -user $name -xdev -type f -ls | \
awk '{ sum += $7 } END { print sum / (1024*1024) }'
done | awk "\$2 > $MAXDISKUSAGE { print \$0 }" > $violators
if ¿ ! -s $violators Á ; then
echo "No users exceed the disk quota of ${MAXDISKUSAGE}MB"
cat $violators
exit 0
fi
while read account usage ; do
cat << EOF | fmt | mail -s "Warning: $account Exceeds Quota" $account
Your disk usage is ${usage}MB, but you have been allocated only
${MAXDISKUSAGE}MB.
|
|
Print this Story |
|
Send Us Feedback |
|
E-mail this Story |
|
Digg this Story |
|
Slashdot this Story |
|
|
|
|
|
|
All Zones Application Performance Zone Business Continuity Zone Data Center Management Zone Enterprise-Class Security Zone The File Data Management Zone Grid Computing on Windows Zone Security Management Zone ITIL Best Practices Zone The SAS Zone Storage Virtualization Zone Business Intelligence and Analytics Zone |
|
|
| ||||||||
| ||||||||
| ||||||||
|

Intercept Spam & Viruses With MessageLabs MessageLabs is offering a complimentary 30 day trial of its managed Anti-virus and Anti-spam security solutions. MessageLabs guarantees complete protection against all know and unknown email threats. By providing 24 hour support, your business can increase productivity and decrease risk. Register for a complimentary trial and receive a free datasheet.Download this white paper now!
|

| Detect, identify, and locate RF interference in 802.11 WLANs. AnalyzeAir software provides IT network professionals with the vision they need into the hidden world of RF, providing them with the ability to see the spectrum in a visible and intelligible format. AnalyzeAir software lets you see, monitor, analyze, and manage all the RF sources and wireless devices that influence your Wi-Fi network's performance and security, even if those devices are unauthorized or transient. AnalyzeAir Trial Software v3.1 highlights the features found in AnalyzeAir Software using a set of saved spectrum files. Replay the data and experience the visibility that AnalyzeAir Wi-Fi Spectrum Analyzer provides. Note: The trial software is limited to a player version only. It does not communicate with an AnalyzeAir PC card so it does not collect actual spectrum data. Register for this trial now.
|
| About Us Advertise Contacts Editorial Calendar Help Desk Jobs at IDG Privacy Policy Reprints Site Map |
|
CIO The Industry Standard |