#!/usr/bin/perl -w
use Expect;
my $exp = new Expect;
my $command = 'ssh -l user 101.102.103.255';
$exp->spawn($command) or die "Cannot spawn $command: $!\n";
my $patidx = $exp->expect(30, 'Enter passphrase for key');
$exp->send("password\n");
$patidx = $exp->expect(30, 'Enter your choice');
$exp->send("r\n");
$patidx = $exp->expect(30, 'Enter IP address');
$exp->send("192.168.1.33\n");
$patidx = $exp->expect(30, 'Enter passphrase for key');
$exp->send("password\n");
$patidx = $exp->expect(30, 'hostname-zh-01 promptstring');
$exp->send("su -\n");
$exp->interact();
|
|
#!/usr/bin/expect
spawn ssh -l user 101.102.103.255
expect "Enter passphrase for key"
stty -echo
send "password\r"
stty echo
expect "Enter your choice"
send "r\r"
expect "Enter IP address"
send "192.168.1.33\r"
send "c\r"
expect "Enter passphrase for key"
send "password\r"
send "c\r"
expect "hostname-zh-01 promptstring"
send "su -\r"
interact
|