Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > net::ssh and functions

Reply
Thread Tools

net::ssh and functions

 
 
usaims
Guest
Posts: n/a
 
      03-09-2007
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(0x91134c'

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 Removed)', $variable );


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

 
Reply With Quote
 
 
 
 
J. Gleixner
Guest
Posts: n/a
 
      03-09-2007
usaims wrote:
> 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(0x91134c'
>
> 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 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';
 
Reply With Quote
 
 
 
 
usaims
Guest
Posts: n/a
 
      03-10-2007
On Mar 9, 6:02 pm, "J. Gleixner" <(E-Mail Removed)>
wrote:
> usaims wrote:
> > 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(0x91134c'

>
> > 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 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';- 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.

 
Reply With Quote
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      03-11-2007
usaims <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> On Mar 9, 6:02 pm, "J. Gleixner" <(E-Mail Removed)>
> wrote:
> > usaims wrote:
> > > 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(0x91134c'

> >
> > > 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 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';- 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.


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(0x91134c".
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
 
Reply With Quote
 
usaims
Guest
Posts: n/a
 
      03-15-2007
On Mar 11, 11:10 am, (E-Mail Removed)-berlin.de wrote:
> usaims<(E-Mail Removed)> wrote in comp.lang.perl.misc:
>
>
>
>
>
> > On Mar 9, 6:02 pm, "J. Gleixner" <(E-Mail Removed)>
> > wrote:
> > >usaimswrote:
> > > > 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(0x91134c'

>
> > > > 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 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';- 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.

>
> 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(0x91134c".
> 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.
>
> Anno- Hide quoted text -
>
> - Show quoted text -



 
Reply With Quote
 
Peter J. Holzer
Guest
Posts: n/a
 
      03-15-2007
On 2007-03-15 20:59, usaims <(E-Mail Removed)> wrote:
> On Mar 11, 11:10 am, (E-Mail Removed)-berlin.de wrote:
>> usaims<(E-Mail Removed)> wrote in comp.lang.perl.misc:
>> > On Mar 9, 6:02 pm, "J. Gleixner" <(E-Mail Removed)>
>> > 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(0x91134c'

[...]
>> 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(0x91134c".
>> 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


--
_ | Peter J. Holzer | Blaming Perl for the inability of programmers
|_|_) | Sysadmin WSR | to write clearly is like blaming English for
| | | http://www.velocityreviews.com/forums/(E-Mail Removed) | the circumlocutions of bureaucrats.
__/ | http://www.hjp.at/ | -- Charlton Wilbur in clpm
 
Reply With Quote
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      03-15-2007
usaims <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> On Mar 11, 11:10 am, (E-Mail Removed)-berlin.de wrote:
> > usaims<(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Static functions and C++ member functions mafiQ C++ 0 04-22-2009 08:33 PM
Does ruby have a similar functions to the Python dir and help functions? py Ruby 5 03-24-2007 08:54 AM
private virtual functions and pure virtual functions with bodies John Goche C++ 10 12-08-2006 04:00 PM
Shared functions vs Non-Shared Functions tshad ASP .Net 11 05-27-2005 05:53 PM
please help me in distinguish redefining functions, overloading functions and overriding functions. Xiangliang Meng C++ 1 06-21-2004 03:11 AM



Advertisments