diff options
author | Christian Pointner <equinox@helsinki.at> | 2010-04-06 15:27:52 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2010-04-06 15:27:52 (GMT) |
commit | d2b849fd657d99968545a3d4ddfe25033f19bb94 (patch) | |
tree | 289de8758de2a427ffcc8dc2c944df4560c94dfa /rhimport.pm | |
parent | 17c903fbd62a82d888d3bf844d89fe095269dd72 (diff) |
added scp put function
Diffstat (limited to 'rhimport.pm')
-rw-r--r-- | rhimport.pm | 27 |
1 files changed, 26 insertions, 1 deletions
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"; |