send-config.pl
changeset 7 19ba8f130480
parent 6 e7973168471d
child 8 ea17020436be
--- a/send-config.pl	Wed Jul 28 13:25:06 2010 +0200
+++ b/send-config.pl	Thu Jul 07 10:11:36 2011 +0200
@@ -1,11 +1,13 @@
 #!/usr/bin/perl -w
 
 use strict;
+use warnings;
+
 use File::Basename;
 use Pod::Usage;
 use Getopt::Long;
 use Config::Tiny;
-use Net::SSH qw(sshopen2);
+use Net::SSH qw(ssh_cmd);
 use Sys::Hostname::Long;
 use Socket;
 use IO::File;
@@ -62,15 +64,15 @@
     my $dest_path = $path . $source_host;
 
     # create remote destination directory
-    my $command = "mkdir -m 0700 -p $dest_path";
+    my $ssh_cmd_args = {
+	    user => $username,
+	    host => $dest,
+	    command => 'mkdir',
+	    args => [ '-m 0700', "-p $dest_path" ],
+    };
+    ssh_cmd $ssh_cmd_args unless $opt_dry_run;
 
-    unless ($opt_dry_run) {
-        sshopen2( "$username\@$dest", *READER, *WRITER, "$command" )
-          || die "ssh: $!";
-    }
-    debug("PROG ssh command: ssh $username\@$dest $command") if $opt_debug;
-    close(READER);
-    close(WRITER);
+    debug("PROG ssh command: ssh $username\@$dest $ssh_cmd_args->{command} ", join ' ', @{$ssh_cmd_args->{args}}) if $opt_debug;
 
     rsync( $username, $dest, $dest_path, $stamp );
 
@@ -145,6 +147,7 @@
         open( STDERR, ">&TMP" ) or die "$!";
         open( STDOUT, ">/dev/null" ) unless $opt_verbose;
         exec @cmd;
+	warn "Failed to exec '", join ' ', @cmd, "': $!\n";
     }
     else {
         waitpid $pid, 0;
@@ -159,10 +162,9 @@
         unlink "/tmp/$ME.$$";
 
         while (<TMP>) {
-            if (/(.*)(?<=failed:)\s+(.*)\s*\(\d+\)/) {
-                push @status, "[WARNING] $1 $2"
-                  unless ( $opt_keepgoing and !$opt_dry_run );
-            }
+		chomp;
+                push @status, "[WARNING] $_"
+                  unless $opt_keepgoing and !$opt_dry_run;
         }
         close(TMP);
     }