Wednesday, October 23, 2013

using expect scripting in perl simple example

Small example is given below. I hope it is self explanatory.
use Expect;
my $command = 'ssh';
my $params = ("$Username\@$Server");
my $exp = new Expect;
# Create the Expect object
$exp->spawn($command, $params)
# Wait for Password prompt to show up
$exp->expect($timeout, ["Password:"]);
# Sent the ssh password
# Wait for command prompt of remote machine
$exp->expect($timeout, ["root\@localhost"]);

No comments: