Or you could add while ($exp->pid()) { $exp->send("exit\n"); }
right after the $exp->interact(); to just keep sending 'exits' while the ssh connection is still open :)
The pid is not closing the process as expected.
Next to this is that this is hanging the script to be closed.
Also the second option to just keep sending an exit also closes sessions at times that I'm still logged into the device.. I suspect that when there is an option of doing a expect in the interact will solve my issue. The point is that all options I have tried failed.