walkingthecow has asked for the wisdom of the Perl Monks concerning the following question:
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..
On reading the Expect doc, I see there's an exitstatus() method documented - could you not utilise that, respawning as necessary, before running the next command ?
A user level that continues to overstate my experience :-))