[TriLUG] Over quota script
Jon Carnes
jonc at nc.rr.com
Sun Sep 15 21:51:32 EDT 2002
Try something like this:
#! /bin/bash
#
# Check for users that are over quota.
# Assume all user dirs are under /home
# look for folks above 40000kb (quota)
#
# Walk the users data tree to find the directory totals
cd /home
du -k > /root/tmp/guber
#
# Setup the marker for over/under quota folks
echo "40000 ###target###" > /root/tmp/guber2
#
# Isolate the users directory - toss away the subdir info
for i in `dir /home`
do
grep -w ./$i$ /root/tmp/guber >> /root/tmp/guber2
done
#
# Sort the directories by size
sort -n </root/tmp/guber2 >/root/tmp/guber3
#
# Throw away info on users less than or equal to quota
LINE=`grep -n "###target###" /root/tmp/guber3 |cut -f1 -d:`
LINE=$(( $LINE + 1 ))
sed -n "$LINE,$ p" /root/tmp/guber3 > /root/tmp/guber4
#
# Stop if there are no users over quota
CHK=`head -1 /root/tmp/guber4`xxx
if [ "xxx" == "$CHK" ]; then
exit 0
fi
#
# Email list of abusers to mis at mydomain.com
# then send out stock message to each abuser
cat /root/tmp/guber4 |mail -s "Folks over quota" mis at mydomain.com
for i in `cat /root/tmp/guber4 |cut -f2 -d/`
do
cat /root/overquota.txt |mail -s "U R over quota: server alpha" $i
done
===
This is all from memory so it may not be 100%, still it should be a good
framework to start from. I used something very like this at a former
employer.
Let me know if you have any questions are comments -- and yes I know it
could be made more efficient. As I said, this is from memory...
Jon
======
On Sun, 2002-09-15 at 13:56, Jeff Bollinger wrote:
> Does anyone have any good shell scripts that warn users they are reaching
> a disk quota (whether or not actual disk quotas are on or enforced)? I'm
> thinking, run du and export a text file, then grep that file for the
> userids that are above a certain limit, and e-mail a canned message to the
> user. This should be something that can run from the cron.
>
> Thanks!
> Jeff
>
> Jeff Bollinger
> University of North Carolina
> IT Security Analyst
> 105 Abernethy Hall
> mailto: jeff_bollinger at unc dot edu
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.0.6 (GNU/Linux)
> Comment: For info see http://www.gnupg.org
>
> iEYEARECAAYFAjzETQsACgkQvoVlxVBmgsXunQCg1Pjc14nTjWiP8FCy+NNDK97E
> HMAAoIRhikBeM5Lm+6Iu/0h3MX6lDgiR
> =LpiV
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> TriLUG mailing list
> http://www.trilug.org/mailman/listinfo/trilug
> TriLUG Organizational FAQ:
> http://www.trilug.org/~lovelace/faq/TriLUG-faq.html
More information about the TriLUG
mailing list