Purging frozen messages from Exim

There’s probably a better way to do this. (If so, leave a comment!) However, I run a debian server for a small task and use the default MTA Exim for mail delivery of status updates to my main mail accounts. Usually I run Postfix or Sendmail. I even have to support Qmail on occasion. However Exim is unfamiliar territory for me — I’m an Exim n00b.

Recently I decided I wanted to remove the “frozen” messages seen by running the mailq command. For example:


# mailq
48h 1.6K 1NUQLB-0007BC-QL <> *** frozen ***
user@domain.tld

48h 1.6K 1NUQO9-0007CW-1u <> *** frozen ***
user@domain.tld

48h 1.6K 1NUQOG-0007CY-1f <> *** frozen ***
user@domain.tld

48h 1.6K 1NUQOG-0007CZ-1v <> *** frozen ***
user@domain.tld

48h 1.6K 1NUQP4-0007DH-Af <> *** frozen ***
user@domain.tld

I know they’ll be purged eventually, I just wanted to clear the queue for some quick testing I was performing. The documentation I found on-line mentioned running “exim -Mrm <id>” for each message id in the mailq output. Being lazy, I don’t want to run that each time — I want a simple one-line command to purge frozen messages. So, I wrote the following BASH script that parses the mailq output and executes the command for each message id:

for i in `mailq | awk '$6 ~ /^frozen$/ {print $3}'`; do exim -Mrm $i; done

Worked like a charm! Message queue emptied of frozen messages.

Summarizing Apache Activity on an Unfamiliar Server

Ever log into a UNIX-like system and need to find what’s happening with Apache or lighttpd? Sure, on a server you’ve set up you can use apache-top or mod_status, but on a server needing attention NOW and one you’ve never logged into what can you do? Well, I wrote a simple one-liner to help.

This is one ugly one-liner. It’s also useful on an unfamiliar server (UNIX-y) to find popular virtual hosts and scripts without knowing too much about the implementation details of Apache or lighttpd for that server. To try it log into a system running Apache or lighttpd with superuser privileges (due to the netstat -ltpn and lsof dependencies) and then Copy/Paste on the command line.

Here’s output on a dev machine with almost no traffic (a busy server is much more interesting):

-------/var/log/apache2/this-access.log------02.Nov.2009:

1	02	03.10 - 03.19	00K
1	02	04.00 - 04.09	00K
1	02	08.40 - 08.49	00K
103	02	11.00 - 11.09	26K
1	02	11.30 - 11.39	00K
1	02	15.40 - 15.49	00K
1	02	16.30 - 16.39	00K
1	02	17.20 - 17.29	00K
-------/var/log/apache2/other_vhosts_access.log------02.Nov.2009:

-------/var/www/sites/other.otr/logs/ins.pect.me-access.log------02.Nov.2009:

The output line shows the number of hits, day of the month, time in 10 min increments and kilobytes of transfer. If an IP had triggered the limits for TOPFILES or TOPIPS there would be a list of those IPs and popular request targets by number of occurrences for the given timeframe.

Bad Behavior has blocked 185 access attempts in the last 7 days.