#!/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 = ""; for (split /\n/, $arg) { 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; $arg = ""; for (@ARGV) { s/([\\\n])/\\$1/g; $arg .= "$_\n"; } $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 "$!"; }