Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
The following works for me. (I just have to answer ssh's "password:" prompt on my local keyboard, 'cuz I don't have those nifty ssh keys for the hosts I connect to from home, but that's no problem.)

I decided to make a simple, general-purpose command line utility out of it, because I actually do this sort of transfer often enough myself to make it worthwhile (now I don't have to remember to put in all those parens, etc, on the command line).

update: added more error checking and support for the "-l username" ssh option; also allow for "$src_path" to be empty (i.e., in login user's home directory).

#!/usr/bin/perl # Program: ssh-tar.perl # Written by: dave graff # Purpose: make it easy to tar from remote-host to local-host use strict; my $Usage = "Usage: $0 hostname [-l username] path-to-tar local-dir-to +-save-to\n"; my $ssh_user = ""; if ( @ARGV > 2 && $ARGV[0] eq "-l" ) { $ssh_user = "$ARGV[0] $ARGV[1]"; shift; shift; } die $Usage unless ( @ARGV == 3 and -d $ARGV[2] and -w $ARGV[2] ); my $local_path = pop; chdir $local_path or die "can't chdir to $local_path: $!\n"; my $src_host = $ARGV[0]; my $divide = rindex( $ARGV[1], "/" ); my $src_path = ( $divide < 0 ) ? "" : substr( $ARGV[1], 0, $divide ); my $src_targ = substr( $ARGV[1], $divide +1 ); my $cmd = "ssh $ssh_user $src_host 'cd $src_path && tar cf - $src_targ +' | tar xf -"; print "command line is:\n\n $cmd\n\n"; system( $cmd );

In reply to Re: tar from another server by graff
in thread tar from another server by Anonymous Monk

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: (14)
    As of 2015-07-02 17:32 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 (44 votes), past polls