Changeset 2609


Ignore:
Timestamp:
Sep 9, 2014, 8:35:03 PM (8 years ago)
Author:
mitchb
Message:
Spammers get you coming and going

Enhance prune-mailq to be able to give you a list of top offenders,
either by sender or by first recipient, and to allow you to purge
all mail from a specific sender or all mail solely destined for a
specific recipient.  Also fix a tiny bit of grammar.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/server/fedora/config/etc/scripts/prune-mailq

    r2426 r2609  
    55
    66usage="Usage:
    7     $0 list
     7    $0 list-from
     8    $0 list-to
    89    $0 show-rand
    910    $0 email lockers...
    10     $0 purge lockers..."
     11    $0 purge-from lockers...
     12    $0 purge-to lockers..."
    1113
    1214clean_locker() {
     
    1416}
    1517
    16 list() {
    17     echo "Top twenty users by number of queued messages:"
     18list_from() {
     19    echo "Top twenty senders by number of queued messages:"
     20    mailq | tail -n +2 | grep -v '^ *(' | awk 'BEGIN { RS = "" } { print $7 }' | sort | uniq -c | sort -n | tail -n 20
     21}
     22
     23list_to() {
     24    echo "Top twenty recipients by number of queued messages:"
    1825    mailq | tail -n +2 | grep -v '^ *(' | awk 'BEGIN { RS = "" } { print $8 }' | sort | uniq -c | sort -n | tail -n 20
    1926}
     
    3138    sender=${SSH_GSSAPI_NAME%%/*}
    3239    if [[ $# -eq 0 ]]; then
    33         echo "Please specific a locker to generate template for." >&2
     40        echo "Please specify a locker to generate template for." >&2
    3441        exit 1
    3542    fi
     
    5764}
    5865
    59 purge() {
     66purge_from() {
    6067    if [[ $# -eq 0 ]]; then
    61         echo "Please specific a locker to purge emails for." >&2
     68        echo "Please specify a locker to purge emails from" >&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 = \"\" } (\$7 == \"$locker@scripts.mit.edu\") { print \$1 }" | tr -d '*!' | postsuper -d -
     75        echo
     76    done
     77}
     78
     79purge_to() {
     80    if [[ $# -eq 0 ]]; then
     81        echo "Please specify a locker to purge emails to" >&2
    6282        exit 1
    6383    fi
     
    7797
    7898case "$op" in
    79     list) list;;
     99    list-from) list_from;;
     100    list-to) list_to;;
    80101    show-rand) show_rand;;
    81102    email) tmpl_email "$@";;
    82     purge) purge "$@";;
     103    purge-from) purge_from "$@";;
     104    purge-to) purge_to "$@";;
    83105    *)
    84106        echo "$usage" >&2;
Note: See TracChangeset for help on using the changeset viewer.