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

In reply to perl-expect interact command by Frits

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.