You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from sh import Server
server = Server(host=...)
server.ls() # Use like sh
Or:
with Server(host=...) as s:
s.ls()
If you are not planning to implement this feature, could you provide some hints on how should one proceed to adapt sh to it? There are other alternatives that do that such as Pyfra (https://github.com/EleutherAI/pyfra) but I enjoy sh's simplicity and syntax.
Thanks for your time in any case.
The text was updated successfully, but these errors were encountered:
There's no plans for this. It's a cool idea though, but making it work is very non-trivial (and requiring a libssh dependency) and starts to change what ssh was originally designed for, which is launching (local) subprocesses. The best that you'll be able to do is by using sh.ssh and reconnecting for each command.
Note that ssh (at least the OpenSSH implementation, which is what you're probably getting with the ssh command) supports creating a single connection which is then reused.
The relevant config option is ControlMaster and the relevant command-line option is -M.
Basically, you can build your own context manager on top of sh.ssh pretty easily:
in __enter__,
start one ssh command that connects and starts the master connection - and doesn't run anything on the server, but also doesn't do anything,
leave this command running in the background, and
return sh.ssh with the arguments to reuse the master connection already bound to it (I think this package calls it "baked", but either way it's partial application of arguments).
in __exit__, terminate the ssh master connection process.
Hi, many thanks for your library, it's very convenient.
I'd like to use it to execute commands in a remote machine via ssh. I'm aware of: https://amoffat.github.io/sh/tutorials/interacting_with_processes.html but I need to keep the ssh connection instead of reconnecting each time. Something like:
Or:
If you are not planning to implement this feature, could you provide some hints on how should one proceed to adapt sh to it? There are other alternatives that do that such as Pyfra (https://github.com/EleutherAI/pyfra) but I enjoy sh's simplicity and syntax.
Thanks for your time in any case.
The text was updated successfully, but these errors were encountered: