All pastes #1318677 Raw Edit

perl using tar over ssh

public text v1 · immutable
#1318677 ·published 2009-01-26 16:30 UTC
rendered paste body
use IPC::Open3;

($command = $0) =~ s#.*/##;            # Use # as delimiter (simpler expr)
($bindir = $0) =~ s#/$command##;
# $bindir = "./";

$rcp = "/usr/bin/scp";
$rsh = "/usr/bin/ssh -l cs ";

open(my $in,  "<",  "lista.txt");
@fetchfiles = <$in>;
$tpcno = 89;
$tpc = "tpc089";
$fsize= $#fetchfiles+1;
print "About to fetch $fsize.\n";
@rcpout = ();

if ($childspid = open3(TWTR,TRDR,TERR, "$rsh cs\@$tpc tar cf - --files-from=- -C video | tar tvf - | wc -l" )) {
		for (@fetchfiles){
			@dest = split(/\//);
			$_ = $dest[$#dest];
			print(TWTR "$_\n");
			print $i++;
		}
	close(TWTR);
	@rcpout = <TRDR>;
	close(TRDR);
	@rcperr = <TERR>;
	close(TERR);
	if ($rcperr || ($rcpout[0] != @fetchfiles)) {
		chop($rcperr);
		if($rcperr){
			print($tpcno, ' - TPC Download error: ',"@rcperr");
		}else {
			$rc = $rcpout[0];
			print($tpcno, ' - TPC Download error: ',"read $rc files instead of $fsize");
		}
		return;
	}
	else {
		print "Successfully fetched $fsize files.\n";
	}
	wait;
}else {
	print "failed open3: $childspid \n";
}