Created
November 11, 2020 16:08
-
-
Save treydock/240167c26bfa858fc8c656f89197f056 to your computer and use it in GitHub Desktop.
Test SSH expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"os" | |
"regexp" | |
"time" | |
expect "github.com/google/goexpect" | |
) | |
var ( | |
passRE = regexp.MustCompile("password:") | |
) | |
func main() { | |
cmd := "ssh repo" | |
timeout := time.Duration(5) * time.Second | |
e, _, err := expect.Spawn(cmd, timeout, expect.Verbose(true), expect.VerboseWriter(os.Stdout)) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer e.Close() | |
content, matches, err := e.Expect(passRE, timeout) | |
if err != nil { | |
log.Fatalf("error getting password prompt: %v", err) | |
} | |
log.Printf("content1: %s matches1: %v", content, matches) | |
err = e.Send(os.Getenv("PASSWORD") + "\n") | |
if err != nil { | |
log.Fatalf("error sending password: %v", err) | |
} | |
content, matches, err = e.Expect(regexp.MustCompile(`\[tdockendorf@repo ~\]\$`), timeout) | |
if err != nil { | |
log.Fatalf("error getting prompt: %v", err) | |
} | |
log.Printf("content2: %s matches2: %v", content, matches) | |
err = e.Send("hostname\n") | |
if err != nil { | |
log.Fatalf("error sending command1: %v", err) | |
} | |
content, matches, err = e.Expect(regexp.MustCompile(`\[tdockendorf@repo ~\]\$`), timeout) | |
if err != nil { | |
log.Fatalf("error getting prompt: %v", err) | |
} | |
log.Printf("content3: %s matches3: %v", content, matches) | |
err = e.Send("/tmp/test.sh\n") | |
if err != nil { | |
log.Fatalf("error sending command2: %v", err) | |
} | |
content, matches, err = e.Expect(regexp.MustCompile(`\[tdockendorf@repo ~\]\$`), timeout) | |
if err != nil { | |
log.Fatalf("error getting prompt2: %v", err) | |
} | |
log.Printf("content4: %s matches4: %v", content, matches) | |
e.Send("exit\n") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LINES=( | |
DISK,0.0,PRIMARY,ARCHIVEPOOL,DEVCLASS | |
DISK,0.0,PRIMARY,BACKUPPOOL,DEVCLASS | |
DCFILEE,27.4,PRIMARY,EPFDHG,DEVCLASS | |
DCFILEE,26.9,PRIMARY,EPFESS,DEVCLASS | |
DCFILEE,0.0,PRIMARY,EPFEXPPROJ,DEVCLASS | |
DCFILEE,0.0,PRIMARY,EPFGPFS,DEVCLASS | |
DCFILEE,0.0,PRIMARY,EPFHOME,DEVCLASS | |
DCFILEE,0.0,PRIMARY,EPFHSM,DEVCLASS | |
DCFILEE,0.0,PRIMARY,EPFNETAPP,DEVCLASS | |
DCFILEE,0.0,PRIMARY,EPFNETSYS,DEVCLASS | |
DCFILEE,0.0,PRIMARY,EPFXTRN,DEVCLASS | |
DCULT7E,0.6,PRIMARY,EPTDHG,DEVCLASS | |
DCULT6E,0.5,PRIMARY,EPTDHG6,DEVCLASS | |
DCULT7E,1.3,PRIMARY,EPTESS,DEVCLASS | |
DCULT6E,20.9,PRIMARY,EPTESS6,DEVCLASS | |
DCULT6E,0.0,PRIMARY,EPTUSRPROJ,DEVCLASS | |
DCFILE,0.0,PRIMARY,PFEXPPROJ,DEVCLASS | |
DCFILE,34.3,PRIMARY,PFGPFS,DEVCLASS | |
DCFILE,0.0,PRIMARY,PFHSM,DEVCLASS | |
DCFILE,47.3,PRIMARY,PFNETAPP,DEVCLASS | |
DCFILE,0.0,PRIMARY,PFNETSYS,DEVCLASS | |
DCULT7,0.0,PRIMARY,PTEXPPROJ,DEVCLASS | |
DCULT6,0.0,COPY,PTEXPPROJCP,DEVCLASS | |
DCULT7,35.3,PRIMARY,PTGPFS,DEVCLASS | |
DCULT7,0.0,COPY,PTGPFSCP,DEVCLASS | |
DCULT7,0.0,PRIMARY,PTHSM,DEVCLASS | |
DCULT7,7.2,PRIMARY,PTNETAPP,DEVCLASS | |
DCULT7,0.0,COPY,PTNETAPPCP,DEVCLASS | |
DCULT7,0.0,PRIMARY,PTNETSYS,DEVCLASS | |
DCULT7,0.0,COPY,PTNETSYSCP,DEVCLASS | |
DISK,0.0,PRIMARY,SPACEMGPOOL,DEVCLASS | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment