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

Last change on this file since 2409 was 2409, checked in by adehnert, 11 years ago
mailq-cleaning script Script to help cleaning postfix mailqueues by listing top users, showing random emails, generate template emails, and prune all emails from a user. This is a partial fix of Scripts-#361.
  • Property svn:executable set to *
File size: 2.4 KB
Line 
1#!/bin/sh
2
3set -eu
4shopt -s failglob
5
6usage="Usage:
7    $0 list
8    $0 show-rand"
9
10show_rand() {
11    files=$(ls /var/spool/postfix/deferred/?/* | shuf | head -n 3)
12    for file in $files; do
13        echo ">>>> $file";
14        strings "$file"
15        echo;
16    done
17}
18
19tmpl_email() {
20    sender=${SSH_GSSAPI_NAME%%/*}
21    if [[ $# -eq 0 ]]; then
22        echo "Please specific a locker to generate template for." >&2
23        exit 1
24    fi
25    for locker in "$@"; do
26        echo "fs la /mit/$locker/"
27        fs la "/mit/$locker"
28        echo
29        cat <<-EOF
30The scripts.mit.edu servers currently have a large number of email
31messages destined for the *$locker* account that are not being handled by
32your account and are being queued. Sufficiently large numbers of queued
33messages can cause stability issues for the servers, so we would like
34you to ensure that your account can handle all messages it receives by
35two weeks from now.
36
37You will be able to process the incoming messages if you sign up for the
38mail scripts service (http://scripts.mit.edu/mail/). You're welcome to
39simply forward all incoming mail to another address (the default is to
40forward it to the mit.edu address of the user who signs up); otherwise,
41you can configure mail scripts to process the incoming messages in some
42suitable fashion.
43
44Frequently, large numbers of queued messages are a sign that some wiki,
45blog, forum, or other site has been spammed. If this is the case, you
46should 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        echo "$locker..."
66        mailq | tail -n +2 | grep -v '^ *(' | awk "BEGIN { RS = \"\" } (\$8 == \"$locker@scripts.mit.edu\" && \$9 == \"\") { print \$1 }" | tr -d '*!' | postsuper -d -
67        echo
68    done
69}
70
71op=${1:-}
72shift
73case $op in
74    list)
75        mailq | tail -n +2 | grep -v '^ *(' | awk 'BEGIN { RS = "" } { print $8 }' | sort | uniq -c | sort -n
76        ;;
77    show-rand) show_rand;;
78    email) tmpl_email "$@";;
79    purge) purge "$@";;
80    *)
81        echo "$usage" >&2;
82        exit 1
83        ;;
84esac
85
86# vim: set sts=4 sw=4 et:
Note: See TracBrowser for help on using the repository browser.