From b5ca8f3cc622c80ec20e3a115adb9d47d9983f75 Mon Sep 17 00:00:00 2001 From: Joe Date: Mon, 18 Dec 2023 20:20:20 +0100 Subject: cool --- c_exec.go | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'c_exec.go') diff --git a/c_exec.go b/c_exec.go index eab792a..0759526 100644 --- a/c_exec.go +++ b/c_exec.go @@ -54,8 +54,31 @@ import ( "strconv" ) +func exec_cmd(cmd_fmt []string) { + cmd := exec.Command(cmd_fmt[0], cmd_fmt[1:]...) + + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + cmd.Run() +} + +func format_cmd(id uint64, lhost *HostList) { + curr := lhost.head + var cmd_fmt []string + + curr = lhost.sel(id) + if curr == 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) + exec_cmd(cmd_fmt) +} + func display_servers(lhost *HostList) { curr := lhost.head + if lhost.head == nil { fmt.Println("no hosts") return @@ -65,14 +88,5 @@ func display_servers(lhost *HostList) { curr = curr.next } fmt.Println() - curr = lhost.sel(3) - if curr == nil { - c_die("host id not found", nil) - } - fmt.Println ("ssh", "-i", curr.Priv, "-p", strconv.Itoa(int(curr.Port)), curr.User + "@" + curr.Host) - cmd := exec.Command("ssh", "-i", curr.Priv, "-p", strconv.Itoa(int(curr.Port)), curr.User + "@" + curr.Host) - cmd.Stdin = os.Stdin - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - cmd.Run() + format_cmd(3, lhost) } -- cgit v1.2.3