net::ssh and functions

U

usaims

Hello:

This is my objective. I'm trying to ssh into a linux node, open a file
and display the contents on my terminal, below is the code. I'm
getting the following error:
bash: -c: line 1: syntax error near unexpected token `0x91134c8'
bash: -c: line 1: `CODE(0x91134c8)'

Does anybody have a clue?
########################################
#!/usr/bin/perl -w
use warnings;
use strict;
use Net::SSH qw(ssh issh sshopen2 sshopen3);
my $variable = \&FUNCTION;

ssh('(e-mail address removed)', $variable );


sub FUNCTION {
open(FILE, "/stuff/log.txt");
print FILE;
}
########################################
 
J

J. Gleixner

usaims said:
Hello:

This is my objective. I'm trying to ssh into a linux node, open a file
and display the contents on my terminal, below is the code. I'm
getting the following error:
bash: -c: line 1: syntax error near unexpected token `0x91134c8'
bash: -c: line 1: `CODE(0x91134c8)'

Does anybody have a clue?
########################################
#!/usr/bin/perl -w
use warnings;
use strict;
use Net::SSH qw(ssh issh sshopen2 sshopen3);
my $variable = \&FUNCTION;

ssh('(e-mail address removed)', $variable );


sub FUNCTION {
open(FILE, "/stuff/log.txt");
print FILE;
}
########################################

You'd be better off using the supported methods, which are well documented.

ssh('user@hostname', $command);

$command is a scalar. e.g. my $command = '/bin/ls /tmp';
 
U

usaims

You'd be better off using the supported methods, which are well documented.

ssh('user@hostname', $command);

$command is a scalar. e.g. my $command = '/bin/ls /tmp';- Hide quoted text -

- Show quoted text -

Thanks, but I need a function there so I can do multiple things while
I'm ssh-ed into the node.
 
A

anno4000

usaims said:
Thanks, but I need a function there so I can do multiple things while
I'm ssh-ed into the node.

First: You may need a function, but not a Perl function, but a function
that ssh can execute on the remote machine.

Second: What you give to ssh is not the Perl function you wrote but
a stringified version of a coderef to the Perl function. In effect,
the $command you are giving to ssh() will look like "CODE(0x91134c8)".
A remote shell won't know what to do with that. That's the error
message you're getting.

Third: If our function is supposed to display the file "/stuff/log.txt",
it won't do that, not even if called correctly as a Perl function. But
the point is moot, you can't (easily) use that on the remote machine
anyhow.

Supposing the remote system is somewhat Unix-like, try
"cat /stuff/log.txt" as the remote command.

Anno
 
U

usaims

First: You may need a function, but not a Perl function, but a function
that ssh can execute on the remote machine.

Second: What you give to ssh is not the Perl function you wrote but
a stringified version of a coderef to the Perl function. In effect,
the $command you are giving to ssh() will look like "CODE(0x91134c8)".
A remote shell won't know what to do with that. That's the error
message you're getting.

Third: If our function is supposed to display the file "/stuff/log.txt",
it won't do that, not even if called correctly as a Perl function. But
the point is moot, you can't (easily) use that on the remote machine
anyhow.

Supposing the remote system is somewhat Unix-like, try
"cat /stuff/log.txt" as the remote command.

Unfortunately, that won't work. I really need to put about 20 lines of
Perl code once I ssh'd into the node. I have to do this accross 80
nodes.
 
P

Peter J. Holzer

usaims said:
On Mar 9, 6:02 pm, "J. Gleixner" <[email protected]>
wrote:
usaimswrote:
This is my objective. I'm trying to ssh into a linux node, open a file
and display the contents on my terminal, below is the code. I'm
getting the following error:
bash: -c: line 1: syntax error near unexpected token `0x91134c8'
bash: -c: line 1: `CODE(0x91134c8)'
[...]
First: You may need a function, but not a Perl function, but a function
that ssh can execute on the remote machine.

Second: What you give to ssh is not the Perl function you wrote but
a stringified version of a coderef to the Perl function. In effect,
the $command you are giving to ssh() will look like "CODE(0x91134c8)".
A remote shell won't know what to do with that. That's the error
message you're getting.

Third: If our function is supposed to display the file "/stuff/log.txt",
it won't do that, not even if called correctly as a Perl function. But
the point is moot, you can't (easily) use that on the remote machine
anyhow.

Supposing the remote system is somewhat Unix-like, try
"cat /stuff/log.txt" as the remote command.

Unfortunately, that won't work. I really need to put about 20 lines of
Perl code once I ssh'd into the node. I have to do this accross 80
nodes.

Then you need to put those 20 lines in a script which you can invoke
from a shell. Ssh can only invoke shell commands. Or you can use some
other mechanism than ssh. Maybe POE or some XML-RPC mechanism. But that
means that you have to run an additional server on each of the 80 nodes.

hp
 
A

anno4000

usaims said:
usaims<[email protected]> wrote in comp.lang.perl.misc:
[...]
Supposing the remote system is somewhat Unix-like, try
"cat /stuff/log.txt" as the remote command.

Unfortunately, that won't work. I really need to put about 20 lines of
Perl code once I ssh'd into the node. I have to do this accross 80
nodes.

Then you'll have to establish a Perl script on each node and run that.
You can transfer the script each time and execute it immediately, if
you want it to work on an unprepared machine.

Anno
 

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


Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top