Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

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>./ bash: -c: line 0: syntax error near unexpected token ` +.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

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (5)
    As of 2018-03-17 23:08 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (227 votes). Check out past polls.