diff options
Diffstat (limited to '')
-rw-r--r-- | c_exec.go | 42 | ||||
-rw-r--r-- | c_init.go | 2 | ||||
-rw-r--r-- | c_parse.go | 8 |
3 files changed, 37 insertions, 15 deletions
@@ -57,36 +57,58 @@ import ( func exec_cmd(cmd_fmt []string) { cmd := exec.Command(cmd_fmt[0], cmd_fmt[1:]...) + fmt.Println(cmd_fmt) cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr cmd.Run() } +func format_ssh(host *HostNode) []string { + cmd_fmt := []string{"ssh"} + user := host.User + + if len(host.Priv) > 0 { + cmd_fmt = append(cmd_fmt, "-i", host.Priv) + } + if host.Port != 0 { + cmd_fmt = append(cmd_fmt, "-p", strconv.Itoa(int(host.Port))) + } + if len(host.User) == 0 { + user = "root" + } + cmd_fmt = append(cmd_fmt, user + "@" + host.Host) + return cmd_fmt +} + +func format_rdp() { +} + func format_cmd(id uint64, lhost *HostList) { - curr := lhost.head + host := lhost.head var cmd_fmt []string - curr = lhost.sel(id) - if curr == nil { + host = lhost.sel(id) + if host == nil { c_die("host id not found", nil) } - cmd_fmt = []string{"ssh", "-i", curr.Priv, "-p", strconv.Itoa(int(curr.Port)), curr.User + "@" + curr.Host} - fmt.Println(cmd_fmt) + if host.Type == 0 { + cmd_fmt = format_ssh(host) + } exec_cmd(cmd_fmt) } func display_servers(lhost *HostList) { - curr := lhost.head + host := lhost.head if lhost.head == nil { fmt.Println("no hosts") return } - for curr != nil { - fmt.Println(curr.ID, curr.Folder + curr.Name) - curr = curr.next + for host != nil { + fmt.Println(host.ID, host.Folder + host.Name) + host = host.next } fmt.Println() - format_cmd(3, lhost) + format_cmd(0, lhost) } @@ -94,7 +94,7 @@ func c_recurse_data_dir(dir string, root string, lhost *HostList) { c_recurse_data_dir(dir + file.Name() + "/", root, lhost) } else if filepath.Ext(file.Name()) == ".yml" { host := c_read_yaml_file(root + dir + file.Name()) - if len(host.Name) == 0 { + if host == nil { return } host.Filename = file.Name() @@ -62,11 +62,11 @@ func c_read_yaml_file(file string) *HostNode { if err = yaml.Unmarshal(yaml_file, &host); err != nil { c_die("error reading yaml file " + file, err) } - if len(host.User) == 0 { - host.User = "root" + if len(host.Name) == 0 { + return nil } - if host.Port == 0 { - host.Port = 22 + if len(host.Host) == 0 { + return nil } return &host } |