go flag.Parse() expect
时间:2021-01-28 12:00:57
收藏:0
阅读:0
package main
import (
"fmt"
"flag"
gexpect "github.com/ThomasRooney/gexpect"
)
func main() {
cmdStr := flag.String("cmd", "", "cmds")
hostStr := flag.String("host", "", "hoststr")
passwd := flag.String("p", "", "passwd")
flag.Parse()
command := "ssh -o ‘StrictHostKeyChecking no‘ -o ConnectTimeout=2 " + *hostStr + " -a " + *cmdStr
child, err := gexpect.Spawn(command)
if err != nil {
panic(err)
}
fmt.Println("-----")
child.Expect("password:")
child.SendLine(*passwd)
child.Interact()
child.Close()
}
评论(0)