#!/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(<STDIN>) {
+ for (split /\n/, $arg) {
chomp;
s/\\(.)/$1/g;
$c .= $_;
}
} 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;
- exit $?;
+ exec "ssh", "$host", "rsc", "-s", encode_base64($arg);
+ die "$!";
}