#!/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 );