From d2b849fd657d99968545a3d4ddfe25033f19bb94 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Tue, 6 Apr 2010 15:27:52 +0000 Subject: added scp put function diff --git a/rhimport.pm b/rhimport.pm index 324dd84..d4c5ab8 100644 --- a/rhimport.pm +++ b/rhimport.pm @@ -25,6 +25,14 @@ use strict; package rhimport; +use IO::Handle; +use IPC::Open3; + +my $ssh_host = "airplay"; +my $ssh_user = "rhimport"; +my $ssh_key_file = "id_dsa"; +my $ssh_dir = "~/.rhimport/"; + sub get_dropboxes { my ($dbh, $user) = @_; @@ -176,6 +184,21 @@ sub import_single return $ret; } +sub scp_put_file { + my ($file) = @_; + my @cmd = ( 'scp', '-prqB' , '-i', $ssh_key_file, $file, "$ssh_user\@$ssh_host:$ssh_dir" ); + my ($reader, $writer, $error ) = ( new IO::Handle, new IO::Handle, new IO::Handle ); + $writer->autoflush(1); + local $SIG{CHLD} = 'DEFAULT'; + my $pid = open3($writer, $reader, $error, @cmd); + waitpid $pid, 0; + my $errstr = ""; + if ( $? >> 8 ) { + my $errstr = join('', <$error>); + } + return $errstr; +} + sub import_file { my ($file, $dropbox) = @_; @@ -183,8 +206,10 @@ sub import_file print " - importing $file to $dropbox .. "; $| = 1; - sleep(1); ### copy file to master server and + my $err = scp_put_file($file); + die $err unless $err eq ""; + ### remotly call rdimport print "Ok\n"; -- cgit v0.10.2