Bindo has asked for the wisdom of the Perl Monks concerning the following question:
Greetings good people. I want to write a script to delete a set of files from one or more remote servers. The ip address of the servers are mentioned in a file called "machines.txt". Note that public key ssh is enabled from source server to the remote hosts.I attempted in a certain direction but no luck. Following is the script.
my @LIBS = ("lib1", "lib2", "lib3"); my $MACHINES_PATH = $ENV{'SYSTEM_HOME'}; my $LIBS_PATH = $MACHINES_PATH."/testlib"; my $MACHINES_LIST = $MACHINES_PATH."/machines.txt"; my $SSH_USER = "abc"; my $SSH_CMD = "/usr/bin/ssh"; open (MYFILE,"<$MACHINES_LIST") or die "Could not open the file $MACHI +NES_LIST, $!"; my @HOSTS = <MYFILE>; foreach my $BOX (@HOSTS) { chomp $BOX; `$SSH_CMD $SSH_USER\@$BOX -o BatchMode=yes ConnectionAttempts=5 Co +nnectTimeout=5 \"cd $LIBS_PATH \&\& files_DEL(@LIBS)"`; } sub files_DEL { my @LIB_FILES = shift; foreach my $lib (@LIB_FILES) { print "deleting file $lib\n"; system("rm -rf $lib"); } }
I'm sure that the sub "files_DEL" has problems. Following is the errors that are returned anyways.
xx@sbi-126:/x02/abc>./filedel.pl bash: -c: line 0: syntax error near unexpected token `libcudart.so.4.1 +.28' bash: -c: line 0: `ConnectionAttempts=5 ConnectTimeout=5 cd /x02/abc/t +estlib && files_DEL(lib1 lib2 lib3)' ssh: Could not resolve hostname : Name or service not known xx@sbi-126:/x02/abc>
Please can someone help. Im still a newbie so appreciate if you could edit my code so i'd understand better. Many thanks in advance
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Removing files from remote server
by salva (Canon) on Apr 22, 2013 at 13:40 UTC | |
Re: Removing files from remote server
by CountOrlok (Friar) on Apr 22, 2013 at 13:52 UTC | |
Re: Removing files from remote server
by pvaldes (Chaplain) on Apr 22, 2013 at 14:03 UTC |
Back to
Seekers of Perl Wisdom