summaryrefslogtreecommitdiff
path: root/rhimport.pm
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2010-04-06 15:27:52 (GMT)
committerChristian Pointner <equinox@helsinki.at>2010-04-06 15:27:52 (GMT)
commit1a2eb99e56ec8b9115752843559c80521f71b96f (patch)
tree289de8758de2a427ffcc8dc2c944df4560c94dfa /rhimport.pm
parentc60c17f22252c2e8cb3ad076013ca496ee31196d (diff)
added scp put function
git-svn-id: https://svn.helsinki.at/rhimport/trunk@34 7c65635b-ec39-4f67-a626-873dbafdd612
Diffstat (limited to 'rhimport.pm')
-rw-r--r--rhimport.pm27
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";