#!/bin/ksh # # $Id: srch,v 1.9 2008/10/01 18:39:18 vogelke Exp $ # # NAME: # srch # # SYNOPSIS: # srch [-ev] [-cfhlmnrstuw] pattern # # DESCRIPTION: # Look through all Estraier DBs for "pattern". # Default behavior (no options) is to search all DBs. # # OPTIONS: # -e exact phrase search: don't insert AND between words # -v print the version and exit # # -c search source-code index # -f search index of mail headers received FROM people # -h search home index # -l search logs index # -m search mail-unread index # -n search notebook index # -p search PDF index # -r search root index # -s search mail-saved index # -t search index of mail headers sent TO people # -u search usr index # -w search web index # # AUTHOR: # Karl Vogel # Sumaria Systems, Inc. lrevno='$RCSfile: srch,v $ $Revision: 1.9 $' lrevdate='$Date: 2008/10/01 18:39:18 $' . /usr/local/lib/ksh/path.ksh . /usr/local/lib/ksh/die.ksh . /usr/local/lib/ksh/usage.ksh . /usr/local/lib/ksh/version.ksh # list just the folders in a directory. folders () { dir=$1 ls -l $dir | grep '^d' | awk '{print $9}' | grep -v '[A-Z]' } # # Command-line options. # sect= exact='no' while getopts ":echlmnprstuvw" opt; do case $opt in c) sect="$sect src" ;; e) exact='yes' ;; h) sect="$sect home" ;; l) sect="$sect logs" ;; m) sect="$sect mail-unread" ;; n) sect="$sect notebook" ;; p) sect="$sect pdf" ;; r) sect="$sect root" ;; s) sect="$sect mail-saved" ;; t) sect="$sect sent" ;; u) sect="$sect usr" ;; w) sect="$sect web" ;; v) version; exit 0 ;; \?) usage "-$OPTARG: invalid option"; exit 1 ;; esac done shift $(($OPTIND - 1)) # # Sanity checks. # top='/search/estraier' test -d "$top" || die "$top: not found" # # If exact search specified, search for that phrase. # If not, create search pattern: "word1 AND word2 AND word3 ..." # Run the search, 40 hits maximum. # Ignore password-checker stuff; that holds dictionaries. # case "$@" in "") usage "no pattern to search for" ;; *) ;; esac case "$exact" in yes) pattern="$@" ;; no) pattern=`echo $@ | sed -e 's/ / AND /g'` ;; esac echo "Searching for: $pattern" # top-level directories are sections. case "$sect" in "") sect=`folders $top` ;; *) ;; esac for db in $sect; do if test -d "$top/$db/srch"; then echo echo "=== $db" estcmd search -sf -vu -max 40 $top/$db/srch "$pattern" | grep -v /src/security/password-checker/ | grep 'file://' | sed -e 's!^.*file://! !' fi done exit 0