Checked in rsc.
[utils.git] / rsc
diff --git a/rsc b/rsc
new file mode 100755 (executable)
index 0000000..a84668d
--- /dev/null
+++ b/rsc
@@ -0,0 +1,41 @@
+#!/usr/bin/perl
+
+if(@ARGV < 1) {
+    print STDERR "usage: rsc HOST CMD ARG...\n";
+    exit 1;
+}
+
+if($ARGV[0] eq "-s") {
+    $c = "";
+    while(<STDIN>) {
+       chomp;
+       s/\\(.)/$1/g;
+       $c .= $_;
+       if(/\\$/) {
+           $c =~ s/\\$/\n/;
+           next;
+       }
+       push @a, $c;
+       $c = "";
+    }
+    for (@a) {
+       exec @a;
+       print STDERR "$a[0]: $!\n";
+       exit 1;
+    }
+} else {
+    $host = shift @ARGV;
+    $pid = open SSH, "|-";
+    if($pid == 0) {
+       exec "ssh", "$host", "rsc", "-s";
+       die "$!";
+    }
+    for (@ARGV) {
+       s/([\\\n])/\\$1/g;
+       print SSH "$_\n";
+    }
+    close SSH;
+    waitpid $pid, 0;
+}
+
+