home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl502b.zip / eg / g / gcp next >
Text File  |  1994-10-18  |  2KB  |  115 lines

  1. #!/usr/bin/perl
  2.  
  3. # $RCSfile: gcp,v $$Revision: 4.1 $$Date: 92/08/07 17:20:15 $
  4.  
  5. # Here is a script to do global rcps.  See man page.
  6.  
  7. $#ARGV >= 1 || die "Not enough arguments.\n";
  8.  
  9. if ($ARGV[0] eq '-r') {
  10.     $rcp = 'rcp -r';
  11.     shift;
  12. } else {
  13.     $rcp = 'rcp';
  14. }
  15. $args = $rcp;
  16. $dest = $ARGV[$#ARGV];
  17.  
  18. $SIG{'QUIT'} = 'CLEANUP';
  19. $SIG{'INT'} = 'CONT';
  20.  
  21. while ($arg = shift) {
  22.     if ($arg =~ /^([-a-zA-Z0-9_+]+):/) {
  23.     if ($systype && $systype ne $1) {
  24.         die "Can't mix system type specifers ($systype vs $1).\n";
  25.     }
  26.     $#ARGV < 0 || $arg !~ /:$/ || die "No source file specified.\n";
  27.     $systype = $1;
  28.     $args .= " $arg";
  29.     } else {
  30.     if ($#ARGV >= 0) {
  31.         if ($arg =~ /^[\/~]/) {
  32.         $arg =~ /^(.*)\// && ($dir = $1);
  33.         } else {
  34.         if (!$pwd) {
  35.             chop($pwd = `pwd`);
  36.         }
  37.         $dir = $pwd;
  38.         }
  39.     }
  40.     if ($olddir && $dir ne $olddir && $dest =~ /:$/) {
  41.         $args .= " $dest$olddir; $rcp";
  42.     }
  43.     $olddir = $dir;
  44.     $args .= " $arg";
  45.     }
  46. }
  47.  
  48. die "No system type specified.\n" unless $systype;
  49.  
  50. $args =~ s/:$/:$olddir/;
  51.  
  52. chop($thishost = `hostname`);
  53.  
  54. $one_of_these = ":$systype:";
  55. if ($systype =~ s/\+/[+]/g) {
  56.     $one_of_these =~ s/\+/:/g;
  57. }
  58. $one_of_these =~ s/-/:-/g;
  59.  
  60. @ARGV = ();
  61. push(@ARGV,'.grem') if -f '.grem';
  62. push(@ARGV,'.ghosts') if -f '.ghosts';
  63. push(@ARGV,'/etc/ghosts');
  64.  
  65. $remainder = '';
  66.  
  67. line: while (<>) {
  68.     s/[ \t]*\n//;
  69.     if (!$_ || /^#/) {
  70.     next line;
  71.     }
  72.     if (/^([a-zA-Z_0-9]+)=(.+)/) {
  73.     $name = $1; $repl = $2;
  74.     $repl =~ s/\+/:/g;
  75.     $repl =~ s/-/:-/g;
  76.     $one_of_these =~ s/:$name:/:$repl:/;
  77.     $repl =~ s/:/:-/g;
  78.     $one_of_these =~ s/:-$name:/:-$repl:/g;
  79.     next line;
  80.     }
  81.     @gh = split(' ');
  82.     $host = $gh[0];
  83.   next line if $host eq $thishost;    # should handle aliases too
  84.     $wanted = 0;
  85.     foreach $class (@gh) {
  86.     $wanted++ if index($one_of_these,":$class:") >= 0;
  87.     $wanted = -9999 if index($one_of_these,":-$class:") >= 0;
  88.     }
  89.     if ($wanted > 0) {
  90.     ($cmd = $args) =~ s/[ \t]$systype:/ $host:/g;
  91.     print "$cmd\n";
  92.     $result = `$cmd 2>&1`;
  93.     $remainder .= "$host+" if
  94.         $result =~ /Connection timed out|Permission denied/;
  95.     print $result;
  96.     }
  97. }
  98.  
  99. if ($remainder) {
  100.     chop($remainder);
  101.     open(grem,">.grem") || (printf stderr "Can't create .grem: $!\n");
  102.     print grem 'rem=', $remainder, "\n";
  103.     close(grem);
  104.     print 'rem=', $remainder, "\n";
  105. }
  106.  
  107. sub CLEANUP {
  108.     exit;
  109. }
  110.  
  111. sub CONT {
  112.     print "Continuing...\n";    # Just ignore the signal that kills rcp
  113.     $remainder .= "$host+";
  114. }
  115.