X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=rsc;h=faa3264a8387d6e639c81be5008d87a7648dd169;hb=091622edf759a120c674d8dd8be67e70c3076a97;hp=32b2b81509197ac2207bc14440092a33e698c4ab;hpb=2c8f92ba91b645fba0456acc6dd885c4681e9e13;p=utils.git diff --git a/rsc b/rsc index 32b2b81..faa3264 100755 --- a/rsc +++ b/rsc @@ -1,40 +1,18 @@ -#!/usr/bin/perl +#!/bin/bash -if(@ARGV < 1) { - print STDERR "usage: rsc HOST CMD ARG...\n"; - exit 1; -} +set -e -if($ARGV[0] eq "-s") { - $c = ""; - while() { - 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; - exit $?; -} +if [ $# -lt 2 ]; then + echo "usage: rsc HOST COMMAND ARGS..." >&2 + exit 1 +fi + +host="$1"; shift +cmd="$1"; shift + +( + echo -n "$cmd"; echo -ne '\0' + for arg in "$@"; do + echo -n "$arg"; echo -ne '\0' + done +) | exec ssh "$host" "xargs -0x sh -c 'exec \$0 \"\$@\"'"