diff --git a/g/cfg.go b/g/cfg.go index 0c98fc1..815cb8a 100644 --- a/g/cfg.go +++ b/g/cfg.go @@ -84,8 +84,8 @@ func GetJsonFile(filePath string) ([]SSHHost, error) { result = m.SshHosts return result, nil } -func WriteIntoTxt(sshResult SSHResult) error { - outputFile, outputError := os.OpenFile(sshResult.Host+".txt", os.O_WRONLY|os.O_CREATE, 0666) +func WriteIntoTxt(sshResult SSHResult, locate string) error { + outputFile, outputError := os.OpenFile(locate+sshResult.Host+".txt", os.O_WRONLY|os.O_CREATE, 0666) if outputError != nil { return outputError } diff --git a/g/const.go b/g/const.go index 71090c5..6f88939 100644 --- a/g/const.go +++ b/g/const.go @@ -5,6 +5,7 @@ package g // 0.1.2 fix ssh error on h3c switch // 0.2 // 0.2.1 +// add write locate file const ( - VERSION = "0.2.1" + VERSION = "0.2.2" ) diff --git a/main.go b/main.go index 50982ec..439e461 100644 --- a/main.go +++ b/main.go @@ -29,6 +29,7 @@ func main() { cfgFile := flag.String("c", "", "cfg File Path") jsonMode := flag.Bool("j", false, "print output in json format") outTxt := flag.Bool("outTxt", false, "write result into txt") + fileLocate := flag.String("f", "", "write file locate") linuxMode := flag.Bool("l", false, "In linux mode,multi command combine with && ,such as date&&cd /opt&&ls") timeLimit := flag.Int("t", 30, "max timeout") numLimit := flag.Int("n", 20, "max execute number") @@ -143,12 +144,13 @@ func main() { //gu if *outTxt { for _, sshResult := range sshResults { - err = g.WriteIntoTxt(sshResult) + err = g.WriteIntoTxt(sshResult, *fileLocate) if err != nil { log.Println("write into txt error: ", err) return } } + return } if *jsonMode { jsonResult, err := json.Marshal(sshResults) @@ -156,11 +158,12 @@ func main() { log.Println("json Marshal error: ", err) } fmt.Println(string(jsonResult)) - } else { - for _, sshResult := range sshResults { - fmt.Println("host: ", sshResult.Host) - fmt.Println("========= Result =========") - fmt.Println(sshResult.Result) - } + return } + for _, sshResult := range sshResults { + fmt.Println("host: ", sshResult.Host) + fmt.Println("========= Result =========") + fmt.Println(sshResult.Result) + } + }