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 messages destined for the *$locker* account that are not being handled by your account and are being queued. Sufficiently large numbers of queued messages can cause stability issues for the servers, so we would like you to ensure that your account can handle all messages it receives by two weeks from now. |
---|
43 | |
---|
44 | You will be able to process the incoming messages if you sign up for the mail scripts service (http://scripts.mit.edu/mail/). You're welcome to simply forward all incoming mail to another address (the default is to forward it to the mit.edu address of the user who signs up); otherwise, you can configure mail scripts to process the incoming messages in some suitable fashion. |
---|
45 | |
---|
46 | Frequently, large numbers of queued messages are a sign that some wiki, blog, forum, or other site has been spammed. If this is the case, you should apply some appropriate spam-blocking mechanism. |
---|
47 | |
---|
48 | If you have any questions, feel free to contact us. |
---|
49 | |
---|
50 | Thanks, |
---|
51 | scripts.mit.edu team |
---|
52 | scripts@mit.edu --- semi-private |
---|
53 | scripts-root@mit.edu --- service maintainers only |
---|
54 | EOF |
---|
55 | echo;echo |
---|
56 | done |
---|
57 | } |
---|
58 | |
---|
59 | purge() { |
---|
60 | if [[ $# -eq 0 ]]; then |
---|
61 | echo "Please specific a locker to purge emails for." >&2 |
---|
62 | exit 1 |
---|
63 | fi |
---|
64 | for locker in "$@"; do |
---|
65 | locker=$(clean_locker "$locker") |
---|
66 | echo "$locker..." |
---|
67 | mailq | tail -n +2 | grep -v '^ *(' | awk "BEGIN { RS = \"\" } (\$8 == \"$locker@scripts.mit.edu\" && \$9 == \"\") { print \$1 }" | tr -d '*!' | postsuper -d - |
---|
68 | echo |
---|
69 | done |
---|
70 | } |
---|
71 | |
---|
72 | op=${1:-} |
---|
73 | |
---|
74 | # We want to go ahead and show the usage message if there are no args, so |
---|
75 | # don't let the shift fail and end the script because of "set -e" |
---|
76 | shift || : |
---|
77 | |
---|
78 | case "$op" in |
---|
79 | list) list;; |
---|
80 | show-rand) show_rand;; |
---|
81 | email) tmpl_email "$@";; |
---|
82 | purge) purge "$@";; |
---|
83 | *) |
---|
84 | echo "$usage" >&2; |
---|
85 | exit 1 |
---|
86 | ;; |
---|
87 | esac |
---|
88 | |
---|
89 | # vim: set sts=4 sw=4 et: |
---|