Files
fn_registry/functions/infra/ssh_exec.md
T
egutierrez 560cbf280e feat: funciones SSH para infra — conn, check, exec, download, upload, tunnel
Conjunto completo de funciones SSH para operaciones remotas: conexión,
verificación de host, ejecución de comandos, transferencia de archivos
(upload/download) y gestión de túneles. Incluye tipo SSHConn y tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 22:03:41 +02:00

37 lines
1.1 KiB
Markdown

---
name: ssh_exec
kind: function
lang: go
domain: infra
version: "1.0.0"
purity: impure
signature: "func SSHExec(conn SSHConn, command string) (string, string, int, error)"
description: "Ejecuta un comando en el host remoto via SSH. Retorna stdout, stderr y exit code separados."
tags: [ssh, exec, remote, command]
uses_functions: []
uses_types: [ssh_conn_go_infra]
returns: []
returns_optional: false
error_type: "error_go_core"
imports: [os/exec]
tested: true
tests: ["echo simple", "captura stderr", "exit code no cero", "comando multilinea"]
test_file_path: "functions/infra/ssh_exec_test.go"
file_path: "functions/infra/ssh_exec.go"
---
## Ejemplo
```go
conn := SSHConn{Host: "192.168.1.100", User: "deploy"}
stdout, stderr, code, err := SSHExec(conn, "df -h /")
if err != nil {
log.Fatal(err)
}
fmt.Printf("exit=%d\nstdout:\n%s\nstderr:\n%s\n", code, stdout, stderr)
```
## Notas
Retorna stdout y stderr como strings separados mas el exit code. Si el comando remoto falla (exit code != 0), NO retorna error — el exit code indica el fallo. Solo retorna error si ssh no pudo conectar o ejecutar. Usa BatchMode=yes para evitar prompts interactivos.