X-Git-Url: http://dolda2000.com/gitweb/?p=utils.git;a=blobdiff_plain;f=rsc;h=74be3fdb0a73245240cb0e8f1a28a8e1e1d2cf30;hp=a84668dfc4b859be08f6d98b22571e8d29a65207;hb=f7bd9b51138dbccb7cc2fd27f07ef66d5d2d79cf;hpb=df4993908ecc42e64d585f34cb95d58ad2d07798 diff --git a/rsc b/rsc index a84668d..74be3fd 100755 --- a/rsc +++ b/rsc @@ -1,13 +1,20 @@ #!/usr/bin/perl +use MIME::Base64; + if(@ARGV < 1) { print STDERR "usage: rsc HOST CMD ARG...\n"; exit 1; } if($ARGV[0] eq "-s") { + if(!defined($ARGV[1])) { + print STDERR "rsc: server side needs arguments\n"; + exit 1 + } + $arg = decode_base64($ARGV[1]); $c = ""; - while() { + for (split /\n/, $arg) { chomp; s/\\(.)/$1/g; $c .= $_; @@ -25,17 +32,17 @@ if($ARGV[0] eq "-s") { } } else { $host = shift @ARGV; - $pid = open SSH, "|-"; - if($pid == 0) { - exec "ssh", "$host", "rsc", "-s"; - die "$!"; - } + $arg = ""; for (@ARGV) { s/([\\\n])/\\$1/g; - print SSH "$_\n"; + $arg .= "$_\n"; } - close SSH; - waitpid $pid, 0; + $ea = encode_base64($arg); + $ea =~ s/\n//g; + if(-t STDIN) { + push @sshopts, "-t"; + } + push @sshopts, "-q"; + exec "ssh", @sshopts, "$host", "rsc", "-s", $ea; + die "$!"; } - -