Discussion in 'Perl Misc' started by Nene, May 17, 2012.

  1. Nene

    Nene Guest

    My variable $main::newvar , which holds a very long command will not
    print to screen after '$ssh->run_ssh() or die "SSH process couldn't
    start: $!";'

    #!!/usr/bin/perl -w
    use strict;

    my $ssh = Net::SSH::Expect->new (
    host => "xxxxxxx",
    password=> 'xxxxxx',
    user => 'xxxxxx',
    raw_pty => 1

    print "$main::newvar\n", br; #### It prints here...

    # now start the ssh process
    $ssh->run_ssh() or die "SSH process couldn't start: $!";

    $ssh->waitfor('\[xxxxxxx\@a_box:Standby\].* \#', 3) or die "prompt not
    found after 3 second";

    print "$main::newvar\n", br; It DOES NOT print here.....

    Any help will be greatly appreciated.
    Nene, May 17, 2012
    1. Advertisements

  2. Nene

    Nene Guest

    Correct, It's a typo, I just copied and pasted the code that is giving
    me trouble.
    Ok, thanks.
    It's at the top of the script.
    It is a CGI script (use CGI is at the top of the page)
    The variable doesn't print after the run_ssh command too.
    The 'waitfor' is not an issue here, tested.
    I'm not.
    It's not the waitfor command, it doesn't produce an error, it is
    authenticating and I'm able to run system commands.
    Nene, May 18, 2012
    1. Advertisements

  3. Nene

    Nene Guest

    Ok, I found the error it's producing: Cannot open a pty at /usr/local/
    share/perl5/Net/SSH/ line 120
    I have installed: IO::pty is up to date (1.10).

    Below is the

    116 # this sets the ssh command line
    117 my $ssh_string = $self->{binary} . " $flags $user\@
    119 # creating the Expect object
    120 my $exp = new Expect();
    122 # saving this instance
    123 $self->{expect} = $exp;
    Nene, May 18, 2012
  4. Nene

    Nene Guest

    I found the fix.
    I had to disable SElinux with:
    echo 0 > /selinux/enforce

    Thank you everybody.
    Nene, May 18, 2012
  5. Nene

    Tim McDaniel Guest

    Would you please explain further? I've never used $^W, and from the
    few references I've seen and even the perlvar doc, I thought that it
    was equivalent to "use warnings".
    Tim McDaniel, May 18, 2012
  6. Nene

    Jim Gibson Guest

    From 'perldoc perlvar':

    $^W The current value of the warning switch, initially true if -w
    was used, false otherwise, but directly modifiable. (Mnemonic:
    related to the -w switch.) See also warnings."

    Looks to me like it is more akin to having '-w' in your shebang line,
    so it turns on warnings in use'd modules.
    Jim Gibson, May 18, 2012
  7. Nene

    Tim McDaniel Guest

    I guess things don't percolate down into used modules. At a quick
    glance, I don't see where perlfunc use or require say that it's done
    in a separate lexical scope in which the user/requirer is invisible,
    unless BEGIN (done by use) does it.

    Thank you for the explanation.
    Tim McDaniel, May 19, 2012
  8. Nene

    Tim McDaniel Guest

    OK. I had been thinking of "do" being like, for example, "#include"
    in C or "eval" in perl, but it's not. I had tried to look this up for
    myself in "require" and "use" in perlfunc, but not "do". Having just
    done so, I see

    do '';

    is just like

    eval `cat`;

    except that ... It also differs in that code evaluated with "do
    FILENAME" cannot see lexicals in the enclosing scope; "eval
    STRING" does.

    Thanks for pointing me at the final bit of the docco.
    Tim McDaniel, May 20, 2012
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.