home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl502b.zip / eg / scan / scanner < prev   
Text File  |  1994-10-18  |  2KB  |  88 lines

  1. #!/usr/bin/perl
  2.  
  3. # $RCSfile: scanner,v $$Revision: 4.1 $$Date: 92/08/07 17:20:44 $
  4.  
  5. # This runs all the scan_* routines on all the machines in /etc/ghosts.
  6. # We run this every morning at about 6 am:
  7.  
  8. #    !/bin/sh
  9. #    cd /usr/adm/private
  10. #    decrypt scanner | perl >scan.out 2>&1
  11. #    mail admin <scan.out
  12.  
  13. # Note that the scan_* files should be encrypted with the key "-inquire", and
  14. # scanner should be encrypted somehow so that people can't find that key.
  15. # I leave it up to you to figure out how to unencrypt it before executing.
  16.  
  17. $ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin:/usr/ucb:.';
  18.  
  19. $| = 1;        # command buffering on stdout
  20.  
  21. print "Subject: bizarre happenings\n\n";
  22.  
  23. (chdir '/usr/adm/private') || die "Can't cd to /usr/adm/private: $!\n";
  24.  
  25. if ($#ARGV >= 0) {
  26.     @scanlist = @ARGV;
  27. } else {
  28.     @scanlist = split(/[ \t\n]+/,`echo scan_*`);
  29. }
  30.  
  31. scan: while ($scan = shift(@scanlist)) {
  32.     print "\n********** $scan **********\n";
  33.     $showhost++;
  34.  
  35.     $systype = 'all';
  36.  
  37.     open(ghosts, '/etc/ghosts') || die 'No /etc/ghosts file';
  38.  
  39.     $one_of_these = ":$systype:";
  40.     if ($systype =~ s/\+/[+]/g) {
  41.     $one_of_these =~ s/\+/:/g;
  42.     }
  43.  
  44.     line: while (<ghosts>) {
  45.     s/[ \t]*\n//;
  46.     if (!$_ || /^#/) {
  47.         next line;
  48.     }
  49.     if (/^([a-zA-Z_0-9]+)=(.+)/) {
  50.         $name = $1; $repl = $2;
  51.         $repl =~ s/\+/:/g;
  52.         $one_of_these =~ s/:$name:/:$repl:/;
  53.         next line;
  54.     }
  55.     @gh = split;
  56.     $host = $gh[0];
  57.     if ($showhost) { $showhost = "$host:\t"; }
  58.     class: while ($class = pop(gh)) {
  59.         if (index($one_of_these,":$class:") >=0) {
  60.         $iter = 0;
  61.         `exec crypt -inquire <$scan >.x 2>/dev/null`;
  62.         unless (open(scan,'.x')) {
  63.             print "Can't run $scan: $!\n";
  64.             next scan;
  65.         }
  66.         $cmd = <scan>;
  67.         unless ($cmd =~ s/#!(.*)\n/$1/) {
  68.             $cmd = '/usr/bin/perl';
  69.         }
  70.         close(scan);
  71.         if (open(PIPE,"exec rsh $host '$cmd' <.x|")) {
  72.             sleep(5);
  73.             unlink '.x';
  74.             while (<PIPE>) {
  75.             last if $iter++ > 1000;        # must be looping
  76.             next if /^[0-9.]+u [0-9.]+s/;
  77.             print $showhost,$_;
  78.             }
  79.             close(PIPE);
  80.         } else {
  81.             print "(Can't execute rsh: $!)\n";
  82.         }
  83.         last class;
  84.         }
  85.     }
  86.     }
  87. }
  88.