Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute the scripts over ssh connection #162

Open
tareksalem opened this issue Jan 15, 2023 · 7 comments
Open

Execute the scripts over ssh connection #162

tareksalem opened this issue Jan 15, 2023 · 7 comments

Comments

@tareksalem
Copy link

I found the library is great and covers most of bash scripting, but you know most of the time when you do bash scripting, you do it on remote servers so how can I make the scripts that I write using this library to be executed over ssh, is there something like this for example?

script.SSH("connection here").EXEC()

thank you

@tareksalem tareksalem changed the title Execute the scripts on over ssh connection Execute the scripts over ssh connection Jan 15, 2023
@bitfield
Copy link
Owner

What about something like this:

script.Exec("ssh myhost ls").Stdout()

@tareksalem
Copy link
Author

thanks for your reply, is this work for executing sub commands on that ssh connection using builder pattern?

script.Exec("ssh yhost ls").FIle("filepath").Stdout()

will this work?

@bitfield
Copy link
Owner

We can execute commands remotely using Exec("ssh..."), and append the results to local files using AppendFile, but since the compiled script program is running locally, all of the script operations will apply locally, not on the remote machine—is that what you're asking?

@tareksalem
Copy link
Author

@bitfield
yes, I am asking about why the script operations are runing locally and there is no a mechanism to run them over ssh, I know that I can run command over ssh using Exec("ssh ...remoteCommands") but my question is, why not defining something like a context to tell script library that I am using ssh context now or local context, something like this

script.Context("ssh").ssh("ssh connection here").DoSomeWorkOnRemoteServer().Context("local").doSomeWorkLocally()

@bitfield
Copy link
Owner

Well, how could we do any work on the remote server? Only by executing code there. How can we get the code on to the remote server? We'd have to deploy a binary there. If we can do that, why bother with SSH? Now we can just do the work locally.

@tareksalem
Copy link
Author

@bitfield
mmm, actually it differs from use case to another, my question came from a use case, which is a golang service running and listening for new created servers then this golang service should install some libraries and do some work on these new created servers, the only way to do that is using ssh connection, also in all cases to deploy the binary code on the remote servers you still need to do ssh so why not performing your actions directly on that remote server using the syntax I suggested?

@gedw99
Copy link
Contributor

gedw99 commented Mar 14, 2023

Yeah I have similar use case

I am using script with nats

nats is the Transport , instead of ssh.

The binary ( that imports script ) needs to exist on both sides though !

I was thinking of add NATS as a formal transport provider to Script as a PR but my use case / prototype has not stabilised yet.

nats can stream anything.
You can even bootstrap the client binary onto the server via nats and then your set .

The data and ops are just topics in the same way that file paths are namespaces. It’s pretty nice

you can add nats AAA security too so that only certain user roles can run over certain topics and so certain file paths on the server.

hit me up if your curious for more info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants