Wednesday, October 23, 2013

using expect scripting in perl simple example

Small example is given below. I hope it is self explanatory.
 
#!/usr/bin/perl
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
$exp->send("$Password\n");
# Wait for command prompt of remote machine
$exp->expect($timeout, ["root\@localhost"]);
$exp->send("ls\r");

No comments: