Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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


In reply to Removing files from remote server by Bindo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (4)
    As of 2015-07-06 03:06 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (69 votes), past polls