in reply to Rename all files on remote server to *.bak recursively

Just put an appropriate Shell script on the remote system and then tell the remote, via SSH, to execute that script.   It will find the files locally to itself and then rename them appropriately.   Provide the directory-path as an argument to that remote shell script.   The shell script in question can easily consist of a find -r command, piped to a sed command to remove the file-extension, piped to an xargs rm command with placeholders.   The initiating system does not need to be (and should not be) concerned with the exact list of files that may be present on the remote ... the remote knows best.   All that the initiating system needs to do is to ask the remote to do, within its (the remote’s ...) own local context, what it is an ideal position to do.   The local Captain does not need to know anything about the remote’s directory-status in order to give that remote Private an Order (“Sir!   Yes Sir!!”™) to be carried out competently at the remote location.

Replies are listed 'Best First'.
Re^2: Rename all files on remote server to *.bak recursively
by nancylt723 (Initiate) on Jun 05, 2014 at 21:16 UTC
    Actually, we are talking about over 50 remotes, so this might not be practical. But thanks.
      Then you can run then in parallel combining Net::OpenSSH::Parallel and Net::SFTP::Foreign:
      # untested my @host = ...; my $dir = ...; use Fcntl ':mode'; use Net::OpenSSH::Parallel; use Net::SFTP::Foreign; my $pssh = Net::OpenSSH::Parallel->new; for my $host (@host) { $pssh->add_host($host); } sub sftp_rename { my ($label, $ssh) = @_; my $sftp = $ssh->sftp; $sftp->find($dir, ordered => 1, wanted => sub { my (undef, $entry) = @_; if (S_ISREG($entry->{a}->perm)) { my $fn = $entry->{filename}; $sftp->rename("$fn", "$fn.bak"); } 0; }, ); } $pssh->all(parsub => \&sftp_rename); $pssh->run;

      those 50 remotes can work in parallel, which to me is an argument in favour of having the remotes do the work independently (of course, your local host probably is a multitasking System, too, but ...)