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

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