func copyfile() { color.Yellow("开始执行文件发送:") info, err := os.Lstat(all_ssh.ArgsInfo.File) if err != nil || info.IsDir() { color.Blue("检查要发送的文件.") return } for _, v := range all_ssh.ServerList { go func() { client := all_ssh.Connection(v) if client != nil { all_ssh.CopyFile(client, all_ssh.ArgsInfo.File, all_ssh.ArgsInfo.Dir) } }() } var num int var Over chan os.Signal = make(chan os.Signal, 1) go signal.Notify(Over, os.Interrupt, os.Kill) go result(&num, Over) <-Over color.Yellow("一共有%d条错误.\n", len(all_ssh.ErrorList)) for _, v := range all_ssh.ErrorList { color.Red(v) } color.Red("收到结果:%d条\n", num) }
func main() { if all_ssh.ArgsInfo.IP != "" { color.Yellow("开始登录:%s\n", all_ssh.ArgsInfo.IP) var v all_ssh.ConnetctionInfo for _, v = range all_ssh.ServerList { if v.IP == all_ssh.ArgsInfo.IP { break } } v.IP = all_ssh.ArgsInfo.IP client := all_ssh.Connection(v) if client == nil { return } err := all_ssh.TtyClient(client) if err != nil { println(err.Error()) } if len(all_ssh.ErrorList) >= 1 { color.Red(all_ssh.ErrorList[0]) } return } if all_ssh.ArgsInfo.File != "" { copyfile() return } if all_ssh.ArgsInfo.Cmd != "" { runcmd() return } color.Blue("使用%s -h查看帮助.\n", os.Args[0]) }
func runcmd() { defer File.Close() color.Yellow("开始执行命令:%s\n", all_ssh.ArgsInfo.Cmd) color.Yellow("成功解析%d条记录.\n", len(all_ssh.ServerList)) for _, v := range all_ssh.ServerList { go func(v all_ssh.ConnetctionInfo) { client := all_ssh.Connection(v) if client != nil { all_ssh.Run(client, all_ssh.ArgsInfo.Cmd) } }(v) } var num int var Over chan os.Signal = make(chan os.Signal, 1) go signal.Notify(Over, os.Interrupt, os.Kill) go result(&num, Over) <-Over color.Yellow("一共有%d条错误.\n", len(all_ssh.ErrorList)) for _, v := range all_ssh.ErrorList { color.Red(v) } color.Red("收到结果:%d条\n", num) }