I'm sending a command by SSH. This particular command happens to tell the machine to reboot. Unfortunately this hangs my SSH session and does not return so that my script is unable to continue forwards onto other tasks.
I've tried various combinations of modifying the command itself to include "exit" and or escape commands but in none of those cases does the machine pick up on both the reboot and the command to close the SSH session. I've also tried ConnectTimeout and ClientAlive options for SSH but they seem to make the restart command ignored.
Is there some obvious command that I'm missing here?
Well nobody has posted any answers that pertain to SSH specifically, so I'll propose a
SIGALRM
solution like here: https://stackoverflow.com/a/1191537/3803152This basically sets a timer for 30 seconds, then tries to execute your code. If it fails to complete before time runs out, a
SIGALRM
is sent, which we catch and turn into aTimeoutException
. That forces you to theexcept
block, where your program can continue.Just gonna throw some psuedo-code out there but I would suggest using a flag to denote whether or not you have already rebooted.
rebootState.py
sshCommander.py