in reply to perl expect moudule to interact with Linux terminal

Hi kkbka,

If you have 'expect' installed on your system you can use 'autoexpect -c ssh root@localhost' to create working native expect solution (script.exp). That may give ideas what is wrong with your perl script.

  • Comment on Re: perl expect moudule to interact with Linux terminal

Replies are listed 'Best First'.
Re^2: perl expect moudule to interact with Linux terminal
by kkbka (Initiate) on Mar 30, 2015 at 17:36 UTC

    Thanks for your reply. I tried with autoexpect also but no luck.

    Kindly let me know, how to escape the "#" in perl. I tried like "\#", but its not escaping, instead of that it assumes the following character are commented

      This little piece of code works for me. Beside replacing '???' at $user and $pass you should also replace '\$' with '#' in all three cases.
      use strict; use Expect; my $user = "???"; my $pass = "???"; my $hostname = "localhost"; my $comm1 = "pwd"; my $comm2 = "date"; my $comm3 = "exit"; $Expect::Log_Stdout = 1; my $session = Expect->spawn("ssh $user\@$hostname") or die "Error call +ing external program: $!\n"; $session->expect(5,"password: "); $session->send("$pass\r"); $session->expect(5, "\r \$"); $session->send("$comm1\r"); $session->expect(5, "\r \$"); $session->send("$comm2\r"); $session->expect(5, "\r \$"); $session->send("$comm3\r"); $session->expect(undef);