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

Last change on this file since 2411 was 2411, checked in by adehnert, 9 years ago
prune-mailq: only show the top twenty users
  • Property svn:executable set to *
File size: 2.6 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
43messages destined for the *$locker* account that are not being handled by
44your account and are being queued. Sufficiently large numbers of queued
45messages can cause stability issues for the servers, so we would like
46you to ensure that your account can handle all messages it receives by
47two weeks from now.
48
49You will be able to process the incoming messages if you sign up for the
50mail scripts service (http://scripts.mit.edu/mail/). You're welcome to
51simply forward all incoming mail to another address (the default is to
52forward it to the mit.edu address of the user who signs up); otherwise,
53you can configure mail scripts to process the incoming messages in some
54suitable fashion.
55
56Frequently, large numbers of queued messages are a sign that some wiki,
57blog, forum, or other site has been spammed. If this is the case, you
58should apply some appropriate spam-blocking mechanism.
59
60If you have any questions, feel free to contact us.
61
62Thanks,
63scripts.mit.edu team
64scripts@mit.edu --- semi-private
65scripts-root@mit.edu --- service maintainers only
66EOF
67        echo;echo
68    done
69}
70
71purge() {
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
84op=${1:-}
85shift
86case $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        ;;
95esac
96
97# vim: set sts=4 sw=4 et:
Note: See TracBrowser for help on using the repository browser.