I would change the approach from your script (sending a shell command loop to the remote side) to a three-step approach:
Using the three steps makes it much, much easier to review the list of commands before they are executed.
The relevant parts of the script would be:
# Get list of remote files my @remote_files= qx(ssh $uid $h 'find $dirname');
# Munge filenames to commands: my @commands= map { sprintf "mv -i '%s' '%s.bak'", quotemeta($_), quotemeta($_) } @remote_files;
# Send list of commands to the remote side: # First, a dry-run instead of actually doing that: my $remote= \*STDOUT; # Use this to actually do the remote execution: #open $remote, "| ssh -q -l $uid $h"; print { $remote } join "\n", @commands;
In reply to Re: Rename all files on remote server to *.bak recursively
by Corion
in thread Rename all files on remote server to *.bak recursively
by nancylt723
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |