ssh and Perl

  • Thread starter Gunter Schelfhout
  • Start date
G

Gunter Schelfhout

I'm trying to execute a small Perl-script via ssh like this:
ssh <target_pc> perl -e ' print "hello\n" '

But this doesn't seem to work.

Someone who has an idea?
 
S

Sam Holden

I'm trying to execute a small Perl-script via ssh like this:
ssh <target_pc> perl -e ' print "hello\n" '

But this doesn't seem to work.

Someone who has an idea?

Replace perl with "echo" and see what is actually getting executed at
the other end.

Using ssh like that results in double parsing of the command line, once
locally and once by the remote server. So your single quotes keep the
print and "hello\n" as one argument locally, but then the shell on
the remote end splits them into two arguments...

Use something like:

ssh <target> perl -e "'print qq{hello\n}'"

If you don't want to change quoting styles in the perl then you'll
have to work out the escaping required with your shell yourself - and
it clearly has nothing to do with perl :)
 
G

Gunter Schelfhout

Sam Holden wrote:

[knip]
Use something like:

ssh <target> perl -e "'print qq{hello\n}'"

If you don't want to change quoting styles in the perl then you'll
have to work out the escaping required with your shell yourself - and
it clearly has nothing to do with perl :)

OK. Thanks a lot. This will work.
 
G

Garry Short

Gunter said:
I'm trying to execute a small Perl-script via ssh like this:
ssh <target_pc> perl -e ' print "hello\n" '

But this doesn't seem to work.

Someone who has an idea?

Okay, the most obvious one:
1. What makes you think this belongs in a Perl newsgroup?

Others to think about before you ask on a more relevant newsgroup:
2. Is the SSH connections actually working?
3. Is Perl installed on the remote machine?

HTH,

Garry
 
M

Mothra

Okay, the most obvious one:
1. What makes you think this belongs in a Perl newsgroup?

Others to think about before you ask on a more relevant newsgroup:
2. Is the SSH connections actually working?
3. Is Perl installed on the remote machine?
Come on, that's a bit harsh. He was trying to run some simple Perl code
- that's obviously why he thought it was suitable for a Perl newsgroup.
You've got to start somewhere.

Someone on comp.security.ssh might just as likely have knocked him back to this
group anyway, telling him it's not an SSH issue.

Or maybe he simply believed the hype about Perl coders all being
friendly & helpful? ;-)
 
L

lostriver

I'm trying to execute a small Perl-script via ssh like this:
ssh <target_pc> perl -e ' print "hello\n" '

But this doesn't seem to work.

Someone who has an idea?


Well, you have got enough explanations why you should not ask questions
like this here....

Here is how you can do it:
ssh <target_pc> 'perl -e " print \"hello\n\"" '

Or better yet make it 'a perl question' - install and use Net::SSH::perl
module (pure perl implementation of SSH protocol).
 
G

Garry Short

Mothra said:
Come on, that's a bit harsh. He was trying to run some simple Perl code
- that's obviously why he thought it was suitable for a Perl newsgroup.
You've got to start somewhere.

Someone on comp.security.ssh might just as likely have knocked him back to
this group anyway, telling him it's not an SSH issue.

Or maybe he simply believed the hype about Perl coders all being
friendly & helpful? ;-)

Sorry, it wasn't meant to come across as harsh. It was just extremely
obviously not a perl problem (checking it from a command line, if you're
not sure, takes all of 20 secs). The other two questions were intended to
make sure that he definitely was in a position to at least *try* and do
what he wanted.

However, saying that it's okay to post here, just because there's some perl
code included, is possibly a little too ... "relaxed". That would make it
okay to ask why:

perl -e ' system("ps uax | sort -k2") '

doesn't sort the output by %CPU. Okay, it's a perl script, but what does the
problem have to do with perl?

Regards,

Garry

(the answer, btw, is that sort numbers the columns from 1, not 0, so you'd
want "sort -k3" [on my Linux box, anyway])
 
G

Gunter Schelfhout

See below.

Duh Duh.
Come on, that's a bit harsh. He was trying to run some simple Perl code
- that's obviously why he thought it was suitable for a Perl newsgroup.
You've got to start somewhere.

Well, the thing I was trying to accomplisch was not just some simple Perl code. Well, IMHO.
I made some classes which interact and I have to run a script via eval on a remote machine. Like this:
my $command = q( perl -e "'
my %checks;
\$checks{group} = getgrnam fwcomposer;
\$checks{user} = getpwnam fwcomposer;
\$checks{ssh_dir} = grep { \$_ =~ m#^/etc/fwcomposer/\.ssh\$# }
glob(\"/etc/fwcomposer/.*\");
\$checks{ssh_keys} = grep { \$_ =~ m#^/etc/fwcomposer/\.ssh/fwcomposer.pub\$# }
glob(\"/etc/fwcomposer/.ssh/*\");
print join / /, %checks;
'");
$ret_val = $conn->command($command);

I didn't received any output, not even an error message. So I guessed (wrongly) that it was
the interpreter that didn't give any output to the remote shell, due to the lack of errors.
Apparently, I guessed wrong.
Someone on comp.security.ssh might just as likely have knocked him back to
this group anyway, telling him it's not an SSH issue.

Or maybe he simply believed the hype about Perl coders all being
friendly & helpful? ;-)

I'm also believing that there are some idiots out there who like bashing.

At least Sam gave a solution and a clue that it was indeed SSH who was responsible
for my trouble.
 
M

Matt Garrish

Gunter Schelfhout said:
I'm also believing that there are some idiots out there who like bashing.

There are a few people here who could stand to read something other than the
perldocs. A little philosophy might help them realize that there is no such
thing as a Perl question. And one of those glossy magazines from the top
rack might do wonders for their pent-up frustrations...

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Remote SSH and Configuring code help 0
CGI NET::SSH browser problem 1
Net::SSH::Perl install Hangs 0
installing Net::SSH::Perl 2
system(@ssh) steals stdin 2
ssh tullen 20
ssh tullen 0
Net::SSH forward local port 0

Members online

Forum statistics

Threads
474,121
Messages
2,570,714
Members
47,282
Latest member
hopkins1988

Latest Threads

Top