From 54852076f93380d75a2154ae30a3cbfcca53c9db Mon Sep 17 00:00:00 2001 From: anonpenguin23 Date: Sun, 3 May 2026 14:55:43 +0300 Subject: [PATCH] feat(ssh): allow running remote commands via ssh - update ssh command to accept optional remote command argument - modify sshInto to execute commands non-interactively when provided - comment out unreachable node in nodes.conf --- core/pkg/cli/cmd/sshcmd/ssh.go | 29 +++++++++++++++++++++-------- core/scripts/nodes.conf | 2 +- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/core/pkg/cli/cmd/sshcmd/ssh.go b/core/pkg/cli/cmd/sshcmd/ssh.go index c5955b3..75796b9 100644 --- a/core/pkg/cli/cmd/sshcmd/ssh.go +++ b/core/pkg/cli/cmd/sshcmd/ssh.go @@ -16,13 +16,21 @@ var envFlag string // Cmd is the top-level "ssh" command — SSH into any node by IP or hostname. var Cmd = &cobra.Command{ - Use: "ssh ", + Use: "ssh [-- command]", Short: "SSH into a node", Long: `SSH into a node by IP address or hostname. -Resolves the SSH key from rootwallet automatically.`, - Args: cobra.ExactArgs(1), +Resolves the SSH key from rootwallet automatically. + +Pass a command after the IP to run it non-interactively: + orama ssh 1.2.3.4 'sudo systemctl status orama-node'`, + Args: cobra.MinimumNArgs(1), + DisableFlagParsing: false, RunE: func(cmd *cobra.Command, args []string) error { target := args[0] + remoteCmd := "" + if len(args) > 1 { + remoteCmd = args[1] + } env := envFlag if env == "" { @@ -42,7 +50,7 @@ Resolves the SSH key from rootwallet automatically.`, // Match by IP for _, n := range nodes { if n.Host == target { - return sshInto(n) + return sshInto(n, remoteCmd) } } @@ -52,7 +60,7 @@ Resolves the SSH key from rootwallet automatically.`, Host: target, User: "root", VaultTarget: target + "/root", - }) + }, remoteCmd) }, } @@ -60,7 +68,7 @@ func init() { Cmd.Flags().StringVar(&envFlag, "env", "", "Environment to search (default: active)") } -func sshInto(node inspector.Node) error { +func sshInto(node inspector.Node, remoteCmd string) error { nodes := []inspector.Node{node} cleanup, err := remotessh.PrepareNodeKeys(nodes) if err != nil { @@ -75,12 +83,17 @@ func sshInto(node inspector.Node) error { return fmt.Errorf("ssh not found in PATH: %w", err) } - sshCmd := exec.Command(sshBin, + sshArgs := []string{ "-i", keyPath, "-o", "StrictHostKeyChecking=accept-new", "-o", "IdentitiesOnly=yes", fmt.Sprintf("%s@%s", node.User, node.Host), - ) + } + if remoteCmd != "" { + sshArgs = append(sshArgs, remoteCmd) + } + + sshCmd := exec.Command(sshBin, sshArgs...) sshCmd.Stdin = os.Stdin sshCmd.Stdout = os.Stdout sshCmd.Stderr = os.Stderr diff --git a/core/scripts/nodes.conf b/core/scripts/nodes.conf index 72e4c36..11a34f1 100644 --- a/core/scripts/nodes.conf +++ b/core/scripts/nodes.conf @@ -14,7 +14,7 @@ devnet|ubuntu@51.38.128.56|nameserver-ns3 devnet|ubuntu@144.217.162.62|node devnet|ubuntu@51.83.128.181|node devnet|ubuntu@144.217.160.15|node -devnet|root@46.250.241.133|node +# devnet|root@46.250.241.133|node # TODO: add rootwallet key devnet|root@109.123.229.231|node devnet|ubuntu@144.217.162.143|node devnet|ubuntu@144.217.163.114|node