Auto-delete junk comment/trackback script for MT 3.2

| 3 TrackBacks

Movable Type 3.2 introduced a new status for comments and trackbacks - 'junk'. Rather than blocking comments and trackbacks that are deemed to be spam, such comments and trackbacks are kept in the system. How long these 'junk' comments and trackbacks are kept in the MT database is controlled by following settings, found on the "Feedback" tab of the weblog's "Settings" page:

Auto-Delete Junk:

  • If enabled, junk feedback will be automatically erased after a number of days.

  • This setting controls whether you want to have junk comments and TrackBacks automatically deleted after a certain period of time specified in the next option.

Delete Junk After X days:

  • When an item has been marked as junk for this many days, it is automatically deleted.

  • This setting defines the number of days since a junk comment or TrackBack was received or marked as Junk until the item is deleted.

    The value of this setting depends completely on how often you look in your Junk folder for false positives. The default is 60 days, but most people will be satisfied with 7 days.

When "Auto Delete Junk" is enabled, the deletion of junk comments and trackbacks is not truly automatic (despite what the MT documentation says). MT will only "auto-delete" junk comments and trackbacks when you browse to a weblog's main admin page in MT (the page displayed when click on a weblog's title on the main mt.cgi page). If you never browse to this page, which is surprisingly easy to do with all of the new weblog shortcut links present in MT 3.2, MT will not delete old junk comments and trackbacks.

I receive hundreds of spam comments and trackbacks every day. Assuming an average of 500 spams per day (not an unreasonable number), if I do not trigger an auto-delete of junk comments and trackbacks, my MT database would have 3,500 junk comments and trackbacks stored in it after just 1 week, and 15,000 in just one month (30 days). This is unacceptable to me - I have no need to store that many junk comments and trackbacks ever, taking up large amounts of database and disk space.

I don't want to have to remember to periodically browse to the main admin page of each weblog where comments and trackbacks are enabled just to delete old junk comments and trackbacks, so I created a script to be run from a cron job that will indeed automatically delete junk comments and trackbacks for me. Even if I decide to take a break from weblogging for a week or a month, the script will keep deleting junk comments and trackbacks as they get too old and keep the size of my MT database from growing out of control.

This script can be downloaded / viewed here: expire-junk.txt

To install:

  1. Download the above script.

  2. Rename script to 'expire-junk' (remove the '.txt' extension).

  3. Upload 'expire-junk' script in ASCII mode to server in the MT 'tools' directory.

  4. Set permissions on script to '0755'.

  5. Create cron job to periodically run script. The following is recommended as the command to run:
    cd <mt.cgi directory>; ./tools/expire-junk
    Replace <mt.cgi directory>' with the server path to your mt.cgi directory.

I have "Auto Delete Junk" enabled on my weblogs, with "Delete Junk After" set to 2 days. The expire-junk script does not need to be run very often - I've set my cron job to run expire-junk 2 times a day (every 12 hours). When the expire-junk script runs and junk comments or trackbacks are deleted, the number of comments and trackbacks deleted is logged in the MT Activity Log:

DateIP AddressLog Message
15 hours, 39 minutes ago127.0.0.1ExpireJunk: 4 junk ping(s) deleted from weblog 'The Tweezer's Edge'
15 hours, 39 minutes ago127.0.0.1ExpireJunk: 149 junk comment(s) deleted from weblog 'The Tweezer's Edge'

If no junk comments or trackbacks are deleted, no entry is made to the MT Activity Log.

The run-periodic-tasks script was used as a model for the expire-junk script, then I took the junk expiration code from CMS.pm and tweaked it a little to work in this script. I did consider developing this as a plugin instead, but it would be invoked on every comment and trackback submission, which would impose unnecessary overhead on MT's comment and trackback processing, and the timing of comment/trackback submissions is unpredictable and inconsistent. A script run by cron seemed a much better and cleaner solution to me.

If you find this script useful, let me know. Comments and suggestions welcome.

3 TrackBacks

MT will only "auto-delete" junk comments and trackbacks when you browse to a weblog's main admin page in MT. This script truly automates the procedure through a cron command. Read More

Das Auto-Delete-Script f�r Kommentare und Trackbacks erg�nzt die in MT 3.2 eingebaute Funktion des Junk-Ordners und erledigt selbtst�ndig das L�schen des Spam-Ordners per Cron-Sript. Interessante Erkenntniss bringen Licht in das tats�chliche interne Ha... Read More

SpamLoopUp und der Junk-Ordner haben in den letzten Tagen einigen MT-Anwendern womöglich Knobelaufgaben aufgegeben. Die neue Dokumentation schafft mehr Klarheit. Aber brauche ich wirklich einen Cron-Job zum Löschen des Junk-Ordners? Movable T... Read More

About this Entry

This page contains a single entry by TweezerMan published on September 26, 2005 10:55 AM.

Supreme Court confirmation hearings - John Roberts / Kelo was the previous entry in this blog.

SpamLookup's Keyword Filter Explained is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 6.1.2

MT-Vampire plugin

web hosting by TotalChoice Hosting

Valid XHTML 1.0!
Valid CSS!