Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Perl Expect

by vasug (Initiate)
on Jan 17, 2018 at 11:45 UTC ( [id://1207408]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl Expect
in thread Perl Expect

I run script in Linux environment. I am trying to connect to a box and execute commands, all of sudden the handle gets close/not able to send any command on that expect channel and give error.

Please find sample code snippet: #!/usr/bin/perl use strict; use Expect; my $session = new Expect; $session->spawn("/volume/labtools/bin/nicetelnet -KE $my_ip"); $session->expect(90, -re, "login:"); print $session "regress\r"; $session->expect(90, -re, "Password:"); print $session "MaRtInI\r"; $session->expect(90, -re, ".*"); print $session "pwd\r"; $session->expect(90, -re, ".*"); $session->close(); <\p>

Error: Get below error, when script tries to print "pwd\r" cmmand on the expect handle. ERROR: No such file or directory <\p> Thanks in advance

Replies are listed 'Best First'.
Re^3: Perl Expect
by salva (Canon) on Jan 17, 2018 at 12:05 UTC
    When posting put code inside <code>...</code> tags, please. Otherwise it is quite hard to read.

    What is that nicetelnet thing? using a too clever telnet client my get in the way.

      nicetelnet is just a wrapper on top of telnet. reposing the code.

      #!/usr/bin/perl use strict; use Expect; my $session = new Expect; $session->spawn("telnet $my_ip"); $session->expect(90, -re, "login:"); print $session "regress\r"; $session->expect(90, -re, "Password:"); print $session "MaRtInI\r"; $session->expect(90, -re, ".*"); print $session "pwd\r"; $session->expect(90, -re, ".*"); $session->close()
        Expect provides several methods for retrieving the matching data and also the last error. Have you experimented with them? Expect should be able to detect the slave process has terminated and report it accordingly.

        You could also try Net::Telnet. That module doesn't depend on an intermediate program and shouldn't have any problem detecting a remote closed connection (in case Expect has any).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1207408]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2024-04-23 17:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found