ssh_shell_exec
Send a command to an SSH session, wait for it to finish, and retrieve the output—combining write and read with automatic completion detection.
Instructions
Send a command to an SSH shell session and wait for the output. Combines write + read in one call, with automatic completion detection (marker/prompt). IMPORTANT: Do NOT issue concurrent commands to the same session_id — the SSH shell is a single channel; concurrent calls will interleave output and corrupt results. Always wait for the previous command to finish before sending the next one. If you need parallel execution, open multiple sessions via ssh_shell_open.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| clear | No | Buffer clear flag: 1 (default) = clear buffer before collecting, 0 = append to buffer | |
| command | Yes | The command to send to the shell | |
| timeoutMs | No | Execution cap in ms — MANDATORY on every call: estimate the command's expected runtime and pass it; omit it ONLY when the user explicitly says not to pass a timeout. Suggested estimates: basic instant commands (ls/pwd/echo/cat small files/ip addr/uname) 3000-5000, never above 10000; output-heavy commands (cat large files, dmesg/journalctl with long output, log dumps) 20000-30000; medium tasks (apt install, dd, service restart) 30000-120000; reboot/reset/power-cycle up to 120000; streaming/resident commands (ping/logcat/top, or sampling a fixed window of live output) 10000 (Ctrl+C auto-sent to stop). Do NOT pass 300000 — the 5-minute value is the internal safety-valve fallback only, not a suggested estimate; if a command genuinely needs longer than ~2min, pass an explicit larger value. If omitted, safety-valve defaults apply: resident commands 10000ms (sampling, Ctrl+C sent on timeout), other commands 300000ms (5min fallback, NO interrupt sent — the command may still be running, terminate via send_ctrl if needed). Timeout type is annotated in the returned output. | |
| session_id | Yes | The session ID returned by ssh_shell_open |