Same session for running multiple functions #352
Replies: 2 comments 2 replies
-
A lot depends here on what kind of device you are talking to, and things like whether it supports multiple sessions on the same connection and how it handles activity timeouts. With a server like OpenSSH, there should be no reason to run "func 2" to keep the SSH session alive. At most, you should be able to use the SSH "keep alive" controls to automatically send background traffic when the connection is otherwise idle, to make sure firewalls don't drop state on the connection. Even if the first command takes a long time and isn't generating output, the connection should remain open due to the keepalives. On devices where that's not good enough, I would worry that they might also not support opening multiple sessions on the same connection, or even if they did the inactivity timeout might be applies on a per-session basis. In such cases, I'm not sure there would be a good way to keep the connection alive. You might instead need to figure out what command to send up front to disable or increase the inactivity timeout. As for moving "to the next function", it sounds like you're thinking about doing so without trying to stop the function running in the previous session. This should be possible on devices that allow you to open multiple sessions per connection, but it would be up to you to track how long you want to wait before moving on, and any limits you want to put on the maximum number of sessions you're willing to run in parallel. Using an asyncio Semaphore here could help if you want to put a limit on the total number of parallel sessions you want to open, but by itself that won't put any kind of minimum delay between session startups prior to hitting that limit. |
Beta Was this translation helpful? Give feedback.
-
I just noticed the title here talks about using the "same session" for multiple commands. SSH itself as a protocol doesn't support a concept of more than one command being run on any given session. If you wanted to do something like that, you'd probably be doing so via some kind of interactive shell running on the remote system and taking advantage of its "job control" features. That's certainly possible to do, but none of this would be happening at the SSH protocol level. It would all just be commands and control sequences you send over SSH by writing to stdin on the SSH channel you open. The specifics of how to do this would depend on what remote shell you were using, and not really anything specific to the SSH client or server. |
Beta Was this translation helpful? Give feedback.
-
Hi All,
I am trying to run multiple functions in the same session using ssh. In case a function takes longer then would like to move to the next function and execute and come back to check if the first function completed or not. Is it possible with asyncssh.
My scenario is -
func 1 - Takes about 60-80 min
func 2 - Small command to keep session alive
In this case, I want to keep running func 2 until func 1 completes to keep session alive and exit once func 1 completes.
Beta Was this translation helpful? Give feedback.
All reactions