#!/bin/ksh ################################################################################ # Print a stanza # Here we look in /etc/security/user file and print root's stanza # Finds line starting with root: and ends on first blank line # # Written by Matt Baker mbaker@computeranddata.com ################################################################################ DEBUG=0 #VERBOSE=0 COMMENTCHAR="*" SEPERATORCHAR=":" #OUTSEPERATORCHAR=":" usage () { print "Usage error" print "$0 [-debug] [-c x] [-s y] -p starting-search-pattern -f filename" #print "$0 [-v] [-debug] [-c x] [-s y] [-o z] -p starting-search-pattern -f filename" print "" print " -c comment char default: $COMMENTCHAR" print " -s seperator char default: $SEPERATORCHAR" #print " -o output seperator char default: $OUTSEPERATORCHAR" print "" print "You may have to backslash metacharacters for options." print "i.e -c \#" print "" print "i.e. $0 -p ^\\/usr -f /etc/filesystems" print "i.e. $0 -p ^root: -f /etc/security/user" print "" exit 1 } if (( ! $# )) then print "Usage: must provide an argument." exit 1 fi while (( $# )) do case "$1" in -debug) shift DEBUG=1 set -x ;; # -v) # shift # VERBOSE=1 # ;; -c) shift COMMENTCHAR=$1 shift ;; -s) shift SEPERATORCHAR=$1 shift ;; -o) shift OUTSEPERATORCHAR=$1 shift ;; -p) shift PATTERN=$1 shift ;; -f) shift FILE=$1 shift if [[ ! -f $FILE ]] then print "ERROR:3:File $FILE not found" exit 3 fi ;; *) print "Usage: incorrect argument." usage ;; esac done cat $FILE | grep -v ^$COMMENTCHAR \ | awk '/'$PATTERN''$SEPERATORCHAR'/,/^$/'