source: trunk/server/fedora/config/etc/scripts/prune-mailq @ 2501

Last change on this file since 2501 was 2426, checked in by adehnert, 11 years ago
prune-mailq: don't pre-wrap the sample email
  • Property svn:executable set to *
File size: 2.8 KB
Line 
1#!/bin/sh
2
3set -eu
4shopt -s failglob
5
6usage="Usage:
7    $0 list
8    $0 show-rand
9    $0 email lockers...
10    $0 purge lockers..."
11
12clean_locker() {
13    echo "${1%%@scripts.mit.edu}"
14}
15
16list() {
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
21show_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
30tmpl_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
42The 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
44You 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
46Frequently, 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
48If you have any questions, feel free to contact us.
49
50Thanks,
51scripts.mit.edu team
52scripts@mit.edu --- semi-private
53scripts-root@mit.edu --- service maintainers only
54EOF
55        echo;echo
56    done
57}
58
59purge() {
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
72op=${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"
76shift || :
77
78case "$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        ;;
87esac
88
89# vim: set sts=4 sw=4 et:
Note: See TracBrowser for help on using the repository browser.