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 email@example.com " perl -e '$var=\"a\"; print $var;' "
syntax error at -e line 1, near "="
Execution of -e aborted due to compilation errors.
# ssh firstname.lastname@example.org " perl -e '$var="a"; print $var;' "
(nothing happened. It just returned)
# ssh email@example.com " perl -e 'print \"a\";' "
a (it works without the variable. why?)
# ssh firstname.lastname@example.org "./test_script"
a (it works if I place the perl code in a file first and then execute)
[email@example.com]# 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?