net::ssh and functions

Discussion in 'Perl Misc' started by usaims, Mar 9, 2007.

  1. usaims

    usaims Guest

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


    sub FUNCTION {
    open(FILE, "/stuff/log.txt");
    print FILE;
    }
    ########################################
    usaims, Mar 9, 2007
    #1
    1. Advertising

  2. usaims

    J. Gleixner Guest

    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(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('', $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';
    J. Gleixner, Mar 9, 2007
    #2
    1. Advertising

  3. usaims

    usaims Guest

    On Mar 9, 6:02 pm, "J. Gleixner" <>
    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(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('', $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.
    usaims, Mar 10, 2007
    #3
  4. usaims

    -berlin.de Guest

    usaims <> wrote in comp.lang.perl.misc:
    > On Mar 9, 6:02 pm, "J. Gleixner" <>
    > 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(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('', $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(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
    -berlin.de, Mar 11, 2007
    #4
  5. usaims

    usaims Guest

    On Mar 11, 11:10 am, -berlin.de wrote:
    > usaims<> wrote in comp.lang.perl.misc:
    >
    >
    >
    >
    >
    > > On Mar 9, 6:02 pm, "J. Gleixner" <>
    > > 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(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('', $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(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.
    >
    > Anno- Hide quoted text -
    >
    > - Show quoted text -
    usaims, Mar 15, 2007
    #5
  6. On 2007-03-15 20:59, usaims <> wrote:
    > On Mar 11, 11:10 am, -berlin.de wrote:
    >> usaims<> wrote in comp.lang.perl.misc:
    >> > On Mar 9, 6:02 pm, "J. Gleixner" <>
    >> > 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


    --
    _ | Peter J. Holzer | Blaming Perl for the inability of programmers
    |_|_) | Sysadmin WSR | to write clearly is like blaming English for
    | | | | the circumlocutions of bureaucrats.
    __/ | http://www.hjp.at/ | -- Charlton Wilbur in clpm
    Peter J. Holzer, Mar 15, 2007
    #6
  7. usaims

    -berlin.de Guest

    usaims <> wrote in comp.lang.perl.misc:
    > On Mar 11, 11:10 am, -berlin.de wrote:
    > > usaims<> 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
    -berlin.de, Mar 15, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. loial
    Replies:
    0
    Views:
    391
    loial
    Feb 10, 2009
  2. Tench Johnson
    Replies:
    1
    Views:
    279
    Biff Tannen
    Apr 23, 2010
  3. salamond

    net/ssh in ruby. ssh.exec fails

    salamond, Feb 17, 2011, in forum: Ruby
    Replies:
    0
    Views:
    226
    salamond
    Feb 17, 2011
  4. Deepika
    Replies:
    2
    Views:
    199
    Deepika
    Nov 14, 2006
  5. Replies:
    0
    Views:
    80
Loading...

Share This Page