#!/bin/sh ## Search all rules, sorted by priority (highest at top), with full redundancy. ## Usage: sa-grep-rules [GREP_OPTIONS] [QUERY] ## See `egrep --help' or `man egrep' for help on options or query ## Use "sa-grep-rules -m1 -C3 '\bRULE\b'" for a rule named RULE. ## v0.1 (c)2009 by Adam Katz , Apache License 2.0 or LGPLv2+ ## Based on my sa-rule-info script. # find most recently modified of the given dirs or else failover to /dev/null latest_dir() { ls -td "$@" 2>/dev/null |head -n1 |grep . || echo '/dev/null'; } update_dir=`latest_dir /var/lib/spamassassin*/*/ /var/db/spamassassin*/*/` share_dir=`latest_dir /usr/local/share/spamassassin*/ /usr/share/spamassassin*/` conf_dir=`latest_dir /usr/local/etc/mail/spamassassin*/ /etc/spamassassin*/ \ /etc/mail/spamassassin*/` user_dir=`latest_dir "$HOME/.spamassassin"` # note, this ignores the possibility of spamd --virtual-config-dir # find files in all those dirs that are smaller than 2mb, search for RULE # (local.cf gets priority over other things in $conf_dir) find "$user_dir" "$conf_dir/local.cf" "$conf_dir" "$update_dir" "$share_dir" \ -size -4096 -print0 2>/dev/null |xargs -0 \ egrep "^[^#][^#][^#][^#]" 2>/dev/null \ |grep -v "^Binary file" |sed 's/^[^:]*://g' |egrep ${1:+"$@"}