| 1 | #!/bin/sh |
|---|
| 2 | |
|---|
| 3 | set -eu |
|---|
| 4 | shopt -s failglob |
|---|
| 5 | |
|---|
| 6 | usage="Usage: |
|---|
| 7 | $0 list |
|---|
| 8 | $0 show-rand |
|---|
| 9 | $0 email lockers... |
|---|
| 10 | $0 purge lockers..." |
|---|
| 11 | |
|---|
| 12 | clean_locker() { |
|---|
| 13 | echo "${1%%@scripts.mit.edu}" |
|---|
| 14 | } |
|---|
| 15 | |
|---|
| 16 | list() { |
|---|
| 17 | echo "Top twenty users by number of queued messages:" |
|---|
| 18 | mailq | tail -n +2 | grep -v '^ *(' | awk 'BEGIN { RS = "" } { print $8 }' | sort | uniq -c | sort -n | tail -n 20 |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | show_rand() { |
|---|
| 22 | files=$(ls /var/spool/postfix/deferred/?/* | shuf | head -n 3) |
|---|
| 23 | for file in $files; do |
|---|
| 24 | echo ">>>> $file"; |
|---|
| 25 | strings "$file" |
|---|
| 26 | echo; |
|---|
| 27 | done |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | tmpl_email() { |
|---|
| 31 | sender=${SSH_GSSAPI_NAME%%/*} |
|---|
| 32 | if [[ $# -eq 0 ]]; then |
|---|
| 33 | echo "Please specific a locker to generate template for." >&2 |
|---|
| 34 | exit 1 |
|---|
| 35 | fi |
|---|
| 36 | for locker in "$@"; do |
|---|
| 37 | locker=$(clean_locker "$locker") |
|---|
| 38 | echo "fs la /mit/$locker/" |
|---|
| 39 | fs la "/mit/$locker" |
|---|
| 40 | echo |
|---|
| 41 | cat <<-EOF |
|---|
| 42 | The scripts.mit.edu servers currently have a large number of email |
|---|
| 43 | messages destined for the *$locker* account that are not being handled by |
|---|
| 44 | your account and are being queued. Sufficiently large numbers of queued |
|---|
| 45 | messages can cause stability issues for the servers, so we would like |
|---|
| 46 | you to ensure that your account can handle all messages it receives by |
|---|
| 47 | two weeks from now. |
|---|
| 48 | |
|---|
| 49 | You will be able to process the incoming messages if you sign up for the |
|---|
| 50 | mail scripts service (http://scripts.mit.edu/mail/). You're welcome to |
|---|
| 51 | simply forward all incoming mail to another address (the default is to |
|---|
| 52 | forward it to the mit.edu address of the user who signs up); otherwise, |
|---|
| 53 | you can configure mail scripts to process the incoming messages in some |
|---|
| 54 | suitable fashion. |
|---|
| 55 | |
|---|
| 56 | Frequently, large numbers of queued messages are a sign that some wiki, |
|---|
| 57 | blog, forum, or other site has been spammed. If this is the case, you |
|---|
| 58 | should apply some appropriate spam-blocking mechanism. |
|---|
| 59 | |
|---|
| 60 | If you have any questions, feel free to contact us. |
|---|
| 61 | |
|---|
| 62 | Thanks, |
|---|
| 63 | scripts.mit.edu team |
|---|
| 64 | scripts@mit.edu --- semi-private |
|---|
| 65 | scripts-root@mit.edu --- service maintainers only |
|---|
| 66 | EOF |
|---|
| 67 | echo;echo |
|---|
| 68 | done |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | purge() { |
|---|
| 72 | if [[ $# -eq 0 ]]; then |
|---|
| 73 | echo "Please specific a locker to purge emails for." >&2 |
|---|
| 74 | exit 1 |
|---|
| 75 | fi |
|---|
| 76 | for locker in "$@"; do |
|---|
| 77 | locker=$(clean_locker "$locker") |
|---|
| 78 | echo "$locker..." |
|---|
| 79 | mailq | tail -n +2 | grep -v '^ *(' | awk "BEGIN { RS = \"\" } (\$8 == \"$locker@scripts.mit.edu\" && \$9 == \"\") { print \$1 }" | tr -d '*!' | postsuper -d - |
|---|
| 80 | echo |
|---|
| 81 | done |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | op=${1:-} |
|---|
| 85 | shift |
|---|
| 86 | case $op in |
|---|
| 87 | list) list;; |
|---|
| 88 | show-rand) show_rand;; |
|---|
| 89 | email) tmpl_email "$@";; |
|---|
| 90 | purge) purge "$@";; |
|---|
| 91 | *) |
|---|
| 92 | echo "$usage" >&2; |
|---|
| 93 | exit 1 |
|---|
| 94 | ;; |
|---|
| 95 | esac |
|---|
| 96 | |
|---|
| 97 | # vim: set sts=4 sw=4 et: |
|---|