#!/usr/bin/perl my $h="testapp01"; my $dirname="/home/wasbatsrv/tmp/testbak"; my $uid="wasbatsrv"; my @r_files= qx(ssh $uid\@$h 'find $dirname -type f'); my @remote_files; # Munge filenames to commands: my $x; # The following is necessary because the values in @r_files have # some kind of funky linefeed that chomp does not get rid of foreach my $f (@r_files) { $x = substr($f, 0, -1); push @remote_files, $x; } my @commands = map { sprintf "mv -f '%s' '%s.bak'", $_, $_ } @remote_files; print @commands, join "\n"; my $remote= \*STDOUT; # Use this to actually do the remote execution: open $remote, "| ssh -q -l $uid $h"; print { $remote } join "\n", @commands;