chiark / gitweb /
grep-my-excuses: monitor grub
[bin.git] / exim-kill-menu
1 #! /bin/bash
2 addrs="$(sudo exim -bp | fgrep -A1 '*** frozen ***' | sed -n '/ \{10\}/s/^ *//p' | sort -u)"
3 while [ "$addrs" ]; do
4     declare -a addrindex
5     i=1
6     for addr in $addrs; do
7         printf '%d) %s\n' "$i" "$addr"
8         addrindex[$i]="$addr"
9         i="$(($i + 1))"
10     done
11     max="$(($i - 1))"
12     while :; do
13         printf '#? '
14         read line
15         if [ -z "$line" ]; then
16             break 2
17         elif expr "$line" : '[0-9][0-9]*$' >/dev/null; then
18             exim-kill "${addrindex[$line]}"
19             addrs="$(echo "$addrs" | fgrep -vx -- "${addrindex[$line]}")"
20             break
21         elif expr "$line" : '[0-9]*-[0-9]*$' >/dev/null; then
22             addrstart="${line%%-*}"
23             addrend="${line#*-}"
24             [ "$addrstart" ] || addrstart=1
25             [ "$addrend" ] || addrend="$max"
26             i="$addrstart"
27             tokill=
28             while [ "$i" -le "$addrend" ]; do
29                 tokill="${tokill:+$tokill\\|}${addrindex[$i]}"
30                 addrs="$(echo "$addrs" | fgrep -vx -- "${addrindex[$i]}")"
31                 i="$(($i + 1))"
32             done
33             exim-kill "$tokill"
34             break
35         fi
36     done
37 done