Just a small question about Paramiko: As I understand, the regular exec_command() is just a sender for sending commands to a device, but doesn't store a state of "terminal". On the other hand, there is invoke_shell() which stores the state of "terminal". And as an example, I have a timeout for all users on my device for active sessions, for example 9999 and this is readonly. But I don't want to wait 9999, so I want to change it to 10 sec, just to check if everything works fine, my rules are applied and etc. So I do noprofile bash and set this variable as 10 sec: exec bash --noprofile --norc -c "export TMOUT=10". If I do this using invoke_shell() and send() method I didn't get terminated my session as after 10 sec I do recv(1024) and see an outcome, but I should have received a paramiko.SSHException. And here is the code:
command = f'exec bash --noprofile --norc -c "export TMOUT=10;"'
noprofile_shell = connection.invoke_shell()
noprofile_shell.send(command)
time.sleep(10)
with pytest.raise(paramiko.SSHException):
noprofile_shell.send("pwd")
noprofile_shell.recv(1024)
Did I do something wrong? Or is there any other ways to check it?
Just a small question about Paramiko: As I understand, the regular exec_command() is just a sender for sending commands to a device, but doesn't store a state of "terminal". On the other hand, there is invoke_shell() which stores the state of "terminal". And as an example, I have a timeout for all users on my device for active sessions, for example 9999 and this is readonly. But I don't want to wait 9999, so I want to change it to 10 sec, just to check if everything works fine, my rules are applied and etc. So I do noprofile bash and set this variable as 10 sec: exec bash --noprofile --norc -c "export TMOUT=10". If I do this using invoke_shell() and send() method I didn't get terminated my session as after 10 sec I do recv(1024) and see an outcome, but I should have received a paramiko.SSHException. And here is the code:
command = f'exec bash --noprofile --norc -c "export TMOUT=10;"'
noprofile_shell = connection.invoke_shell()
noprofile_shell.send(command)
time.sleep(10)
with pytest.raise(paramiko.SSHException):
noprofile_shell.send("pwd")
noprofile_shell.recv(1024)
Did I do something wrong? Or is there any other ways to check it?
Share Improve this question edited Mar 17 at 6:38 Ulrich Eckhardt 17.5k5 gold badges31 silver badges60 bronze badges asked Mar 14 at 11:45 Павло РакетаПавло Ракета 294 bronze badges1 Answer
Reset to default 0Find out that this command should be split into the 2:
exec bash --noprofile --norc
export TMOUT=10
And run via send(), (don't fet about /n in the end). And also there will not be
paramiko.SSHException
You will receive
{OSError}OSError('Socket is closed')