Go package for running Linux distributed shell commands via SSH.
I wanted to experiment with distributed SSH commands, and provide a functional replacement for the old, stale omnissh repository.
package main
import "github.com/discoriver/massh"
func main() {
// Create pointers to config & job
config := &massh.Config{}
job := &massh.Job{
Command: "echo hello world",
}
config.SetHosts([]string{"host1", "host2"})
err := config.SetPublicKeyAuth("~/.ssh/id_rsa")
if err != nil {
panic(err)
}
config.SetJob(job)
config.SetWorkerPool(2)
// Make sure config will run
config.CheckSanity()
config.Run()
}
Get the massh package;
go get github.com/DiscoRiver/massh/massh
Right now you can either user this repo as-is, which provides simple usage, or you can import the massh package and use your own behaviour for building and running the Config.
Output is limited to printing a slice of Results. Additional output processing is required for anything fancy. Result is a struct containing the host, the command, and the output (which includes the newline). This should be enough information for all your basic output needs. No status codes are returned.
When specifying a script, it's contents will be added to stdin, and then the following command will be executed to run it on the remote machine;
cat > outfile.sh && chmod +x ./outfile.sh && ./outfile.sh && rm ./outfile.sh