Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First thing I feel the need to mention is that all of this should really be over ssh/scp rather than rsh/rcp. Maybe it's not an option where you are, but I just wouldn't be able to sleep tonight if I didn't at least say something about it here. :-) That being said, the rest of this will apply equally well whichever you use.</p> <p>Without a lot of other details, I'll take a semi-educated guess here. There are two possible modes of operation I can see for what you're doing, depending on your constraints.</p> <p>The first possibility is that your script may be "shipped" to the remote host(s) in question. In that case, make a list of all the hosts you want to cover, and then:</p> <pre><code>bash$ for this_host in `cat file_of_hosts`; do &gt; rcp existing_script $this_host:/wherever/you/want/it/to/live &gt; rsh $this_host '/wherever/you/want/it/to/live/existing_script /remote/target/directory' &gt; done </code></pre> <p>If not, then it becomes a bit messier (warning, untested, ymmv, caveat programmer, etc)...</p> <pre><code>#!/usr/bin/perl # or change this to iterate over a file full of host/path pairs my ($RemoteHost, $TargetDir) = @ARGV; my $Temp = '/tmp'; sub ProcessRemoteDir { my ($host, $path) = @_; # the command is "ell ess space minus one capital eff" my $listCommand = "rsh $host 'ls -1F $path'"; my @dirEntries = qx{ $listCommand }; chomp(@dirEntries); foreach my $item (@dirEntries) { # If it ends in "/" if ($item =~ m/\/\Z/) { my $subDirectory = $path . "/" . $item; ProcessRemoteDir($host, $subDirectory); } # If it *isn't* a symlink, pipe, or socket elsif ($item !~ /(\@|\||\=)\Z/) { # in case one of the file's 'x' bits is set $item =~ s/\*\Z//; my $localCopy = $Temp . "/" . $item; my $remoteCopy = $host . ":" . $path . "/" . $item; my $fetchCommand = "rcp $remoteCopy $localCopy"; system($fetchCommand); # Your current file processing logic should go here, operating on $localCopy my $putCommand = "rcp $localCopy $remoteCopy"; system($putCommand); unlink $localCopy; } } } ProcessRemoteDir($RemoteHost, $TargetDir); __END__ </code></pre> <p>This is depth-first; not sure if that mattered to you. Also note that in the interest of brevity I have left out almost ALL safety checks. A few that come to mind are checking the returns from the system() and qx{} calls, making sure $localCopy isn't a zero-byte file, changing $listCommand (and the processing of @dirEntries) to check file sizes and permissions and ensure they're within whatever limits make sense in this context and environment (and checking that $remoteCopy and $localCopy start off as the same size), ensuring there aren't any embedded "non-standard" characters in the remote file/directory names that might end up messing with the constructed commands, and any number of others. Please do think about where this will be run and on what kinds of files and whatnot before pulling the trigger.</p> <p>If you fill in more details about what you're trying to do, I might be able to get closer to what you need. This will hopefully get you started, though. :-)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload