execute perl one-liner over ssh (problem with quotes)
Posted on 2006-05-19
I'm trying to execute some perl code remotely and I can't seem to figure out what to do with all the quotes. Here is an example:
# ssh firstname.lastname@example.org " perl -e '$var=\"a\"; print $var;' "
syntax error at -e line 1, near "="
Execution of -e aborted due to compilation errors.
# ssh email@example.com " perl -e '$var="a"; print $var;' "
(nothing happened. It just returned)
# ssh firstname.lastname@example.org " perl -e 'print \"a\";' "
a (it works without the variable. why?)
# ssh email@example.com "./test_script"
a (it works if I place the perl code in a file first and then execute)
[firstname.lastname@example.org]# perl -e '$var="a"; print $var;'
a (it works if I execute the code directly on the machine.)
So the code works if I execute on the machine directly or place it in a file first, but the quotes seem to mess up when trying to execute it inside the ssh command. Any ideas?