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 incorrect 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; }