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 / perl / cron.chk < prev    next >
Text File  |  1992-03-10  |  2KB  |  76 lines

  1. #!/bin/sh -- need to mention perl here to avoid recursion
  2. 'true' || eval 'exec perl -S $0 $argv:q';
  3. eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
  4. & eval 'exec /usr/local/bin/perl -S $0 $argv:q'
  5.         if 0;
  6.  
  7. #  Usage: cron.chk.pl [-rd]
  8. #
  9. #  This checks pathnames and files inside the cron files /usr/lib/crontab
  10. # for writability.
  11. #
  12. #  Mechanism:  The commands inside the file /usr/lib/crontab are executed
  13. # by root.  This perl script uses chk_strings.pl for chking for writable
  14. # files/dirs.
  15. #
  16. #  cron.chk.pl will try to find a file in /usr/lib/crontab first (bsd),
  17. # and then if it isn't there, it will look in the any alternate
  18. # possible locations next -- right now, /usr/spool/cron/crontab -- to
  19. # see if a directory exists, and, if it does, it checks all the cron
  20. # files in turn.
  21. #
  22. #  WARNING!
  23. #
  24. #  Spurious messages can occur; a more stringent method (if perhaps less
  25. # careful of a check) would be to test just the 6th field, instead of
  26. # all the fields after the fifth.  Also throwing away /tmp, etc. could
  27. # be a mistake.
  28. #
  29.  
  30. package main;
  31.  
  32. require 'getopts.pl';
  33. require 'glob.pl';
  34. require 'chk_strings.pl';
  35. require 'pathconf.pl';
  36.  
  37. # should also add args to override default crontab locations
  38. die "Usage: $0 [-rd]\n" unless &Getopts('rd') && !@ARGV;
  39.  
  40. $chk_strings'debug = $opt_d;
  41. $chk_strings'recurse = $opt_r;
  42.  
  43. package cron_chk;
  44.  
  45. #  Possible location of crontab file:
  46. $cron = "/usr/lib/crontab";
  47. #  alternate reality locations of crontab file:
  48. @alt_cron = ("/usr/spool/cron/crontabs");
  49.  
  50. if ( ! -s $cron) {
  51.     for (@alt_cron) {
  52.     # are there ever multiple crontab directories?
  53.     (@crons = &'glob("$_/*")), last if -d;
  54.     }
  55.     die "No crontabs?\n" if ! @crons;
  56. }
  57. @crons = ($cron) unless @crons;
  58.  
  59. # ignore /tmp /dev/null and tty stuff
  60. # &'chk_strings ignores all of above
  61. # STILL NEED to ignore stuff after `>'  ??
  62. #   when we add @ignore stuff to &'chk_strings
  63. # @ignore stuff is in &'chk_strings now, do we want to ignore filenames
  64. #   being redirected into .. might as well leave them, let the user decide.
  65.  
  66. # finally, do the checking -- maybe for one, maybe for lots of cron-ites:
  67. for (@crons) {
  68.     if (! -e) {
  69.     warn "$0: $_: $!\n";
  70.     next;
  71.     }
  72.     &'chk_strings($_);
  73. }
  74.  
  75. 1;
  76.