home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / c / cops_104.zip / cops_104 / is_able.chk < prev    next >
Text File  |  1992-03-10  |  2KB  |  81 lines

  1. :
  2. #
  3. #  is_able.chk
  4. #
  5. #   This shell script checks the permissions of all files and directories
  6. # listed in the configuration file "is_able.lst", and prints warning messages
  7. # according to the status of files.  You can specify world or group readability
  8. # or writeability.  See the config file for the format of the configuration
  9. # file.
  10. #
  11. #   Mechanism:  This shell script parses each line from the configure file,
  12. # changes into the directory the file is in, and then uses the "is_able" 
  13. # program to check if any of the directories in question are writable by 
  14. # world/group.  All results are written to standard output.
  15. #
  16. TEST=/bin/test
  17. ECHO=/bin/echo
  18. AWK=/bin/awk
  19. SED=/bin/sed
  20.  
  21. config_file=is_able.lst
  22.  
  23. # where the test is run:
  24. old_dir=`pwd`
  25.  
  26. if $TEST ! -f "$config_file" ; then
  27.     $ECHO "Config file $config_file doesn't exist!"
  28.     exit
  29.     fi
  30.  
  31. #  Read from $dir_list (e.g. "is.chk.lst") what files/dirs to check.
  32. #
  33. # Comments are lines starting with a "#".
  34. #
  35. # /path/to/{dir|file}   World/Group     Read/Write/Both
  36. # as above              {W|w|G|g}       {R|r|W|w|B|b}
  37. #
  38. $AWK '/^#/ {
  39.     next;}
  40.     { world=group=read=write=both=0; \
  41.     # need 3 fields, or format error
  42.     if (NF != 3) next; \
  43.     if ($2 != "W" && $2 != "w" && $2 != "G" && $2 != "g") next; \
  44.     if ($3!="R"&&$3!="r"&&$3!="W"&&$3!="w"&&$3!="B"&&$3!="b") next; \
  45.     for (f=1;f < NF; f++) printf("%s ", $f); \
  46.     print $NF;
  47.     }' $config_file |
  48. while read targets
  49.     do
  50.     #   Use sed, 'cause awk lets me down (line too long) -- then realize
  51.     # I should have used sed anyway.  Lazy bum.
  52.     foo=`echo "$targets" | $SED 's/\(.*\)....$/\1/'`
  53.     args=`echo "$targets" | $SED 's/.*\(...\)$/\1/'`
  54.  
  55.     #  I added this, to change into the directory before checking
  56.     # for writability; the reason?  With long dir pathnames that had
  57.     # lots of files inside, the shell would blow up, trying to expand
  58.     # all the full paths, and stuff it into a single variable.  For
  59.     # instance, a line like this in $config_file:
  60.     #
  61.     #  /usr/foo/bar/cowabunga/* w w
  62.     #
  63.     #  Would expand to "/usr/foo/bar/cowabunga/ls /usr/..."  Need full
  64.     # pathnames, tho!  And it can still blow up, tho it's tougher.
  65.     #
  66.     dir=`echo "$targets" | $SED 's/\(.*\\)\/[^ ]* .*$/\1/'`
  67.  
  68.     if $TEST -n "$dir" -a -d "$dir" ; then
  69.         cd $dir
  70.         fi
  71.  
  72.     for f in $foo
  73.         do
  74. #        echo $dir $f $args
  75.         $old_dir/is_able $f $args
  76.         done
  77.     cd $old_dir
  78.     done
  79.  
  80. # end of script
  81.