I want to automatically provide input to a command in the bash terminal.
Is it possible to programmatically enter a "yes" after than ssh prompt? Here is a script representing the idea.
package main
import (
"bytes"
"io"
"os"
"fmt"
"os/exec"
)
func main() {
c1 := exec.Command("ssh","root@172.30.0.77")
r, w := io.Pipe()
c1.Stdout = w
c1.Stdin = r
c1.Start()
var b bytes.Buffer
b.Write([]byte("yes"))
fmt.Fprintf(&b, "
")
b.WriteTo(os.Stdin)
c1.Wait()
w.Close()
}
# go run login.go
yes
The authenticity of host '172.30.0.77 (172.30.0.77)' can't be established.
RSA key fingerprint is 13:46:96:ff:ab:12:76:0e:24:6e:3e:7a:ee:c0:81:af.
Are you sure you want to continue connecting (yes/no)?