Hey all, I am trying to figure out how to check the status of an Expect spawn.

I am spawning an SSH session like below... my $connect=Expect->spawn(@SSH,$server_name) or die "Cannot spawn this $SSH to $server_name: $!\n";

This works, of course, but if I leave it for 30 minutes it does as it is expected, the connection to server times out and the script then goes into a mode that you see below:
Changing password for bjones ... FAILED: 3:Child PID 9230 exited with status 256
Changing password for bvone ... FAILED: 1:TIMEOUT
Changing password for bzigg ... FAILED: 1:TIMEOUT

As you can see, my SSH session timed out, and yet my script continues to send commands to my Expect object. I am trying to figure out a way to test that my SSH session is still alive before I send each command. The commands are just called with subroutines and they send to the object like so: print $connect "$command $options $user\; echo \$?\r";
Anyway, before the subroutine is called that sends the command, I want to test that the connection is alive, and then if connection is alive I would like to send command, if not then respawn. I can handle the ifs, just not the test.

I am also wondering if an LDAP bind can timeout? I am having the same issue with my LDAP binds, meaning those seem to timeout as well... Slightly off-topic, but just thought I'd throw it in there..

In reply to Expect object spawn status by walkingthecow

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.