Hi All,
at the moment I have a script running that logs me automatically on routers, switches, firewalls, etc. Yet when I want to exit the device I have to do an additional exit to get my script ended. The part I'm looking for is that when interact(); detects my domain-name prompt in the CLI it will send an additional "exit" to log me off a jump-host. This will stop the part for me doing the exit manually.. (PS the interact is needed for me to do additional commands on the device manually)
Any ideas?
part of script is:
my $exp = new Expect;
$exp = Expect->spawn("ssh $username\@domain-name\r");
$exp->expect( $timeout, ('domain-name'));
$exp->send ("ssh admin\@$device\n");
$exp->expect( $timeout,
[ '-re', qr'yes/no', sub { my $exp = shift;
$exp->send("yes\n");
sleep 2;
exp_continue;
}
],
[ '-re', qr'(C|c)onnection refused', sub {my $exp = shift;
print color ("yellow on_red")," ssh not allowed or incorre
+ct password ", color ("yellow on_black"),"\n";
print color ("reset");
$exp->send ("exit\n");
endscript ();
}
],
[ '-re', qr'(P|p)assword', sub {my $exp = shift;
$exp->send ("$cpeenablepassword\n");
$exp->expect( $timeout, ("Finished"));
}
]
);
$exp->send ("terminal length 0\n");
$exp->expect( $timeout, ("#terminal length 0"));
$exp->send ("show disks details\n");
$exp->expect( $timeout, ("#show disks details"));
$exp->send ("show cms info\n");
$exp->expect( $timeout, ("#show cms info"));
$exp->send ("show alarms\n");
$exp->expect( $timeout, ("#show alarms"));
$exp->send ("show accelerator\n");
$exp->expect( $timeout, ("#show accelerator"));
$exp->send ("terminal length 40\n");
$exp->expect( $timeout, ("#terminal length 40"));
$exp->interact();
$exp->hard_close();
endscript ();
}
####### ENDING AND END OF SCRIPT #######
sub endscript {
print "\n\n\n The Session is Closed.!\n\n";
exit 1;
eof;
}