── guests exec ──────────────────────────────────────────────────────────────
()
| 470 | // ── guests exec ────────────────────────────────────────────────────────────── |
| 471 | |
| 472 | func newGuestsExecCmd() *cobra.Command { |
| 473 | cmd := &cobra.Command{ |
| 474 | Use: "exec <vmid> <command>", |
| 475 | Short: "Execute a command inside a guest via QEMU guest agent", |
| 476 | Long: `Execute a shell command inside a running guest. |
| 477 | |
| 478 | For QEMU VMs the command runs via the QEMU guest agent (no SSH to the guest |
| 479 | required). The VM must have the guest agent enabled and running. |
| 480 | On Linux guests the command runs via /bin/sh -c. |
| 481 | On Windows guests it runs via PowerShell. |
| 482 | |
| 483 | For LXC containers the command runs via pct exec over SSH to the Proxmox node |
| 484 | (ssh_user must be configured). The command always runs via /bin/sh -c. |
| 485 | |
| 486 | Note: unlike the command-runner plugin, exec imposes no command whitelist. |
| 487 | The caller is responsible for what they run. Security is enforced by the |
| 488 | Proxmox API token permissions and SSH access granted to this client.`, |
| 489 | Example: ` pvetui guests exec 100 "uptime" |
| 490 | pvetui guests exec 200 "df -h" |
| 491 | pvetui --profile prod guests exec 100 "systemctl status nginx"`, |
| 492 | Args: cobra.ExactArgs(2), |
| 493 | ValidArgsFunction: completeVMIDs, |
| 494 | RunE: runGuestsExec, |
| 495 | } |
| 496 | |
| 497 | cmd.Flags().Duration("timeout", 30*time.Second, "Command execution timeout") |
| 498 | |
| 499 | return cmd |
| 500 | } |
| 501 | |
| 502 | func runGuestsExec(cmd *cobra.Command, args []string) error { |
| 503 | vmid, err := parseVMID(args[0]) |