mirror of
https://github.com/shanghai-edu/multissh.git
synced 2025-12-16 21:37:50 +00:00
完成读取json文件、结果导出为txt文件、超时处理(时限参数可输入) 控制并发访问
This commit is contained in:
parent
9e410eaa21
commit
47366d7696
3 changed files with 141 additions and 45 deletions
|
|
@ -3,9 +3,9 @@ package main
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"net"
|
||||
//"os"
|
||||
"time"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
|
@ -55,29 +55,31 @@ func connect(user, password, host string, port int) (*ssh.Session, error) {
|
|||
|
||||
func dossh(username, password, ip string, cmdlist []string, port int, ch chan string) {
|
||||
session, err := connect(username, password, ip, port)
|
||||
|
||||
if err != nil {
|
||||
ch <- fmt.Sprintf("<%s>", err.Error())
|
||||
//<-chLimit
|
||||
return
|
||||
|
||||
}
|
||||
defer session.Close()
|
||||
|
||||
// cmd := "ls;date;exit"
|
||||
|
||||
stdinBuf, _ := session.StdinPipe()
|
||||
|
||||
//fmt.Fprintf(os.Stdout, "%s", stdinBuf)
|
||||
var outbt, errbt bytes.Buffer
|
||||
session.Stdout = &outbt
|
||||
|
||||
session.Stderr = &errbt
|
||||
|
||||
err = session.Shell()
|
||||
for _, c := range cmdlist {
|
||||
c = c + "\n"
|
||||
stdinBuf.Write([]byte(c))
|
||||
|
||||
}
|
||||
session.Wait()
|
||||
ch <- (outbt.String() + errbt.String())
|
||||
|
||||
//<-chLimit
|
||||
return
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue