aboutsummaryrefslogtreecommitdiffstats
path: root/c_exec.go
diff options
context:
space:
mode:
authorJoe <rbo@gmx.us>2023-12-18 20:20:20 +0100
committerJoe <rbo@gmx.us>2023-12-18 20:20:20 +0100
commitb5ca8f3cc622c80ec20e3a115adb9d47d9983f75 (patch)
treec76f18721e3754b3cfaf500d40c48d1bc74236f0 /c_exec.go
parentup (diff)
downloadhardflip-b5ca8f3cc622c80ec20e3a115adb9d47d9983f75.tar.gz
hardflip-b5ca8f3cc622c80ec20e3a115adb9d47d9983f75.tar.bz2
hardflip-b5ca8f3cc622c80ec20e3a115adb9d47d9983f75.tar.xz
hardflip-b5ca8f3cc622c80ec20e3a115adb9d47d9983f75.tar.zst
hardflip-b5ca8f3cc622c80ec20e3a115adb9d47d9983f75.zip
cool
Diffstat (limited to '')
-rw-r--r--c_exec.go34
1 files changed, 24 insertions, 10 deletions
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)
}