in reply to Perl Expect

Explain in more detail your environment and what your are trying to do and how, and show us the code you have produced so far.

There are several ways to run Expect. There may be other more suitable modules also.

Replies are listed 'Best First'.
Re^2: Perl Expect
by vasug (Initiate) on Jan 17, 2018 at 11:45 UTC
    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

      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()