Link to home
Start Free TrialLog in
Avatar of d_asselin
d_asselinFlag for Canada

asked on

Unix Script

Hi All

 I’m back again with the same script on the use of the command find in a Solaris
Environment.  This time I have a problem with the regex statement specifically this line

GREP_EXCLUDE_DIRs="${GREP_EXCLUDE_DIRs}tcb$|dev$|devices$|proc$|vol$|xfn$|cdrom$|mnt$|fd$|kernel$|opt1$|opt2$|lost+found$"

On the surface it looks good and works. But it is flawed  and this is the problem
I’m creating a list of dir. That are to be exclude from the find.  What actually happens is that any dir that ends or contains for example
The word  dev  also gets exclude.

I want to exlude /dev   and not  /totodev .  I include the complete script
#######################################################################
LC_ALL="C"; export LC_ALL
umask 066
#######################################################################
trap 'rm -f "${Tmp0}" exit 1' 1 2 3 15
rm -f "${Tmp0}"
#######################################################################
if test -x /bin/nawk
then
  AWk="/bin/nawk"
else
  AWk="awk"
fi
#######################################################################
#
# Get the required input
#
# Define directories that need to be fExcluded (multiple folder must be
# separated by commas) or the entire filesystem will be scanned.
# Default value for fExcludeS is N (no dir to be fExcluded).
#
# # 1: Function: parse_args ()
#
parse_args ()
{
  if [ $# -eq 1  ]
  then
    USER_DIRs=`echo $1 | sed 's/,/ /g'`
    GREP_EXCLUDE_DIRs=`echo "^$1" | sed 's/,/\\|^/g'`
"unownde.sh" 127 lines, 4176 characters
# Criteria:  must be specified by the user as a parameter.
# Action:    Don't display the file
#
exclude_find_dirs()
{
  for USER_DIR in $USER_DIRs
  do
    if [ -n "$fExclude" ]
    then
      fExclude="$fExclude -o"
    fi
        SEARCH_PATH=`echo $USER_DIR | sed 's/\// /g' | awk '{print $NF}'`
        fExclude="${fExclude} -name $SEARCH_PATH -prune"
 echo $SEARCH_PATH
  done

  if [ -n "$fExclude" ]
  then
    fExclude="( $fExclude )"
  fi
}
######################################################################
# Make call - Function #1, #2
#
parse_args $@
exclude_find_dirs

######################################################################
# Rule:      fUnowned
# Search:    Search for any object that has an owner whose UID is not
#            registered in /etc/passwd.  Search for any object that
#            has a group-owner whose GID is not registered in /etc/group.
# Criteria:  * must either have no valid owner or no valid group
# Action:    Display directory listing
#
fUnowned='( -nouser -o -nogroup )'

######################################################################
#
# Output unowned files and directories.
######################################################################
GREP_EXCLUDE_DIRs="${GREP_EXCLUDE_DIRs}tcb$|dev$|devices$|proc$|vol$|xfn$|cdrom$|mnt$|fd$|kernel$|opt1$|opt2$|lost+found$"
DIRs=`ls -1ALl / | grep "^d" | egrep -v "$GREP_EXCLUDE_DIRs" | awk '{print "/"$9}'`

if [ -n "${fExclude}" ]
then
        fExclude=`echo "${fExclude} -o"`
fi

 for i in `find / $DIRs $fUnowned -mount -local`; do dirname $i; done | sort | uniq -c | awk '{print $2","$1}''{SUM +=$1}END  {print " Total Count ="  SUM}'

#######################################################################
# Exit.
exit 0
#######################################################################
# End of unowned.sh

ASKER CERTIFIED SOLUTION
Avatar of sentner
sentner
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of d_asselin

ASKER

Perfect  can’t ask for more many thanks

Dan