Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: tar from another server

by graff (Chancellor)
on Dec 06, 2002 at 04:44 UTC ( #217983=note: print w/ replies, xml ) Need Help??


in reply to tar from another server

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 );


Comment on Re: tar from another server
Download Code
Re: Re: tar from another server
by Anonymous Monk on Dec 06, 2002 at 07:11 UTC
    Thank you very very much :) I appreciate your answer!!!
Re: Re: tar from another server
by Anonymous Monk on Dec 08, 2002 at 08:01 UTC
    I think it is an excellent utility. I was able to tar from 
    the $src_host , however just when the job is about done.
    I got the following error. 
    
    tar: Unexpected EOF in archive
    tar: Unexpected EOF in archive
    tar: Error is not recoverable: exiting now
    
    and if I did 
    
    system( $cmd ) == 0 or die "tar failed"
    
    I always got the tar failed and die.
    Do you have any idea why?
    
    thanks!
    
      You may need to be careful about which version of tar is running on the remote host, and which version is running locally. If they're different (e.g. remote host uses a native solaris version, localhost uses gnu version, or whatever), this might cause the sort of problem you observed.

      Apart from that, does the local host get most of the content that you were hoping for? Can you isolate the particular file(s) that didn't get unpacked locally? (If, God forbid, one of the machines involved is using Microsoft text-mode semantics on the data transfer, that is bound to kill it prematurely.)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://217983]
help
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: (9)
As of 2014-07-28 08:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (193 votes), past polls