in reply to safely passing args through ssh
ssh takes a shell command.
# Passing <<echo>> <<$$>> executes <<echo $$>> $ ssh example.com echo '$$' 10920 # Passing <<echo>> <<'$$'>> executes <<echo '$$'>> $ ssh example.com echo ''\''$$'\''' $$ # Passing <<echo '$$'>> executes <<echo '$$'>> $ ssh example.com 'echo '\''$$'\''' $$
So you have to build a shell command.
sub text_to_shell_lit(_) { return $_[0] if $_[0] =~ /^[a-zA-Z0-9_\-]+\z/; my $s = $_[0]; $s =~ s/'/'\\''/g; return "'$s'"; } my $remote_cmd = join ' ', map text_to_shell_lit, perl => ( '-e' => $perl_code ); backticks(ssh => ( '--', $target, $remote_cmd ));
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: safely passing args through ssh
by perl5ever (Pilgrim) on Jul 25, 2011 at 15:06 UTC | |
by ikegami (Patriarch) on Jul 25, 2011 at 18:19 UTC | |
by perl5ever (Pilgrim) on Jul 25, 2011 at 23:02 UTC | |
by ikegami (Patriarch) on Jul 25, 2011 at 23:29 UTC | |
by perl5ever (Pilgrim) on Jul 26, 2011 at 14:56 UTC | |
| |
by ikegami (Patriarch) on Jul 25, 2011 at 18:20 UTC |