df499390 |
1 | #!/usr/bin/perl |
2 | |
535cc97f |
3 | use MIME::Base64; |
4 | |
df499390 |
5 | if(@ARGV < 1) { |
6 | print STDERR "usage: rsc HOST CMD ARG...\n"; |
7 | exit 1; |
8 | } |
9 | |
10 | if($ARGV[0] eq "-s") { |
535cc97f |
11 | if(!defined($ARGV[1])) { |
12 | print STDERR "rsc: server side needs arguments\n"; |
13 | exit 1 |
14 | } |
15 | $arg = decode_base64($ARGV[1]); |
df499390 |
16 | $c = ""; |
535cc97f |
17 | for (split /\n/, $arg) { |
df499390 |
18 | chomp; |
19 | s/\\(.)/$1/g; |
20 | $c .= $_; |
21 | if(/\\$/) { |
22 | $c =~ s/\\$/\n/; |
23 | next; |
24 | } |
25 | push @a, $c; |
26 | $c = ""; |
27 | } |
28 | for (@a) { |
29 | exec @a; |
30 | print STDERR "$a[0]: $!\n"; |
31 | exit 1; |
32 | } |
33 | } else { |
34 | $host = shift @ARGV; |
535cc97f |
35 | $arg = ""; |
df499390 |
36 | for (@ARGV) { |
37 | s/([\\\n])/\\$1/g; |
535cc97f |
38 | $arg .= "$_\n"; |
df499390 |
39 | } |
535cc97f |
40 | exec "ssh", "$host", "rsc", "-s", encode_base64($arg); |
41 | die "$!"; |
df499390 |
42 | } |