in reply to Re^2: perl expect moudule to interact with Linux terminal
in thread perl expect moudule to interact with Linux terminal
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);
|
|---|