Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: safely passing args through ssh

by perl5ever (Pilgrim)
on Jul 25, 2011 at 15:06 UTC ( [id://916535]=note: print w/replies, xml ) Need Help??


in reply to Re: safely passing args through ssh
in thread safely passing args through ssh

I'm not sure this survives a double-ssh call:
print backticks('ssh', 'localhost', '--', 'ssh', 'localhost', '--', +'argcount', text_to_shell_lit('a b c'));
This prints 3 for me.

As I mentioned in the original post, I was doubtful that backslash-escaping could solve the problem, but there still might be a way to do it.

Replies are listed 'Best First'.
Re^3: safely passing args through ssh
by ikegami (Patriarch) on Jul 25, 2011 at 18:19 UTC

    That doesn't look anything like what I wrote. I showed how to contruct a shell command to pass to ssh but you passed 5 arguments after the target, none of which a shell command.

    If you call ssh twice, you have two shell commands to build.

    sub text_to_shell_lit(_) { return $_[0] if $_[0] =~ /^[a-zA-Z0-9_\-]+\z/; my $s = $_[0]; $s =~ s/'/'\\''/g; return "'$s'"; } my $very_remote_cmd = join ' ', map text_to_shell_lit, argcount => ( 'a b c' ); my $remote_cmd = join ' ', map text_to_shell_lit, ssh => ( '--', $very_remote_target, $very_remote_cmd ); backticks(ssh => ( '--', $remote_target, $remote_cmd ));
      Well, then I guess you didn't solve the problem that I stated.

        The problem you stated: "what's a good way of encoding ... so that it will survive an ssh call?"

        Where "D" is the shell's literal parser and "s" is an arbitrary shell command, you want a function "E" that exhibits the following behaviour:

        s = D(E(s)) = D(D(E(s))) = D(D(D(E(s)))) etc

        but there is none.

Re^3: safely passing args through ssh
by ikegami (Patriarch) on Jul 25, 2011 at 18:20 UTC

    Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Node Status?
    node history
    Node Type: note [id://916535]
    help
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others browsing the Monastery: (4)
    As of 2024-07-17 20:25 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?
      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.