home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / cnews.tar / conf / checkfile < prev    next >
Text File  |  1994-08-30  |  887b  |  49 lines

  1. #! /bin/sh
  2. # checkfile [-i] uid gid permpattern filename
  3.  
  4. ign=n
  5. case "$1" in
  6. -i)    ign=y ; shift    ;;
  7. esac
  8. case "$#" in
  9. 1|2|3)    echo "Usage: $0 [-i] uid gid permpattern filename ..." >&2 ; exit 2    ;;
  10. esac
  11.  
  12. uid="$1"
  13. gid="$2"
  14. permp="$3"
  15. shift ; shift ; shift
  16.  
  17. for f
  18. do
  19.     # the ls output with both uid and gid has 9 fields
  20.     # perms links uid gid size date date date name
  21.     ( ls -ld $f ; ls -lgd $f ) |
  22.         awk 'BEGIN {
  23.             uid = "'"$uid"'"
  24.             gid = "'"$gid"'"
  25.             f = "'"$f"'"
  26.         }
  27.         NF == 9 {
  28.             if ($3 != uid)
  29.                 print f, "belongs to user", $3, "not", uid
  30.             if ($4 != gid)
  31.                 print f, "belongs to group", $4, "not", gid
  32.             if ($1 !~ /'"$permp"'/)
  33.                 print f, "has incorrect permissions", $1
  34.             exit    # sometimes ls -l and ls -lg are synonymous
  35.         }'
  36. done >/tmp/cf$$
  37. if test -s /tmp/cf$$
  38. then
  39.     cat /tmp/cf$$
  40.     if test " $ign" = " n"
  41.     then
  42.         status=1
  43.     fi
  44. else
  45.     status=0
  46. fi
  47. rm -f /tmp/cf$$
  48. exit $status
  49.