r22882 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22881‎ | r22882 | r22883 >
Date:14:44, 10 June 2007
Author:river
Status:old
Tags:
Comment:
whinequota: the program to whine about disk quotas
Modified paths:
  • /trunk/tools/tsutils/whinequota (added) (history)
  • /trunk/tools/tsutils/whinequota/Makefile (added) (history)
  • /trunk/tools/tsutils/whinequota/whinequota (added) (history)

Diff [purge]

Index: trunk/tools/tsutils/whinequota/whinequota
@@ -0,0 +1,90 @@
 2+#! /bin/ksh
 3+
 4+fmtsize() {
 5+ sz=$(($1 * 1024))
 6+
 7+ kbyte=1024
 8+ mbyte=$((kbyte * 1024))
 9+
 10+ if [[ $sz -ge $mbyte ]]; then
 11+ echo $((sz / $mbyte)) MB
 12+ else
 13+ echo $((sz / $kbyte)) KB
 14+ fi
 15+}
 16+
 17+fmttime() {
 18+ tm=$1
 19+
 20+ hour=$((60 * 60))
 21+ day=$((hour * 24))
 22+
 23+ if [[ $tm -ge $day ]]; then
 24+ days=$((tm / day))
 25+ hours=$(((tm % day) / hour))
 26+ if [[ $hours -ge 0 ]]; then
 27+ echo $days days, $hours hours
 28+ else
 29+ echo $days days
 30+ fi
 31+ return;
 32+ fi
 33+
 34+ echo $((tm / hour)) hours
 35+}
 36+
 37+# for each user
 38+for user in `cut -d: -f1 /etc/passwd`; do
 39+ # uid fs use quota limit grace inodes quota limit grace
 40+ # 0 /home 339412 0 0 0 5269 0 0 0
 41+ quotatool -d -u $user /home | read quid qfs qused qsoft qhard qgrace qinodes qisoft qihard qigrace
 42+
 43+ # no quota?
 44+ if [[ $qsoft = 0 ]]; then
 45+ continue
 46+ fi
 47+
 48+ # within soft quota?
 49+ if [[ $qused -le $qsoft ]]; then
 50+ continue;
 51+ fi
 52+
 53+ msg=\
 54+'From: whinequota <whinequota@hemlock.knams.wikimedia.org>
 55+To: %5$s <%5$s@ts.wikimedia.org>
 56+Subject: You have exceeded your disk quota.
 57+Reply-To: Wikimedia Toolserver Administrators <ts-admins@wikimedia.org>
 58+
 59+This message was automatically generated by whinequota on %1$s.
 60+
 61+Hello,
 62+
 63+'
 64+
 65+ # within grace period?
 66+ if [[ $qgrace -ge 0 ]]; then
 67+ msg+=\
 68+'Your disk usage on the system "%1$s" is currently %2$s. This exceeds your soft quota of %3$s.
 69+
 70+Please reduce your usage within %4$s, or you will be unable to create any more files.
 71+
 72+If you have any questions, or you would like to request that your quota be increased, please send mail to <ts-admins@wikimedia.org>.
 73+'
 74+ else
 75+ msg+=\
 76+'Your disk usage on the system "%1$s" is currently %2$s. This exceeds your soft quota of %3$s. Additionally, you have exceeded your grace period, and are now unable to create new files.
 77+
 78+Please reduce your usage. If you have any questions, or you would like to request that your quota be increased, please send mail to <ts-admins@wikimedia.org>.
 79+'
 80+ fi
 81+
 82+ msg+=\
 83+'
 84+Regards,
 85+ whinequota (the program to whine about quotas)
 86+'
 87+
 88+ printf "$msg" $(hostname) "$(fmtsize $qused)" "$(fmtsize $qsoft)" "$(fmttime $qgrace)" "$user" \
 89+ | fold -s -w79 \
 90+ | /usr/lib/sendmail -oi -bm -- "$user"
 91+done
Property changes on: trunk/tools/tsutils/whinequota/whinequota
___________________________________________________________________
Added: svn:executable
192 + *
Index: trunk/tools/tsutils/whinequota/Makefile
@@ -0,0 +1,4 @@
 2+PROG = whinequota
 3+BINDIR = /usr/local/sbin
 4+
 5+include ../mk/script.mk

Status & tagging log