xops exec
以下列出命令用法和可用选项。已安装版本支持的参数以 --help 为准。
text
对一个或多个远程主机执行命令,支持批量执行和提权。默认使用远端 Shell;可用 --interpreter 指定解释器,例如 --interpreter bash --launch-dialect posix。
用法示例(兼容 OpenSSH 风格):
xops exec -l root -p 22 192.168.1.11 "uptime"
xops exec -i ~/.ssh/id_rsa -J bastion.example.com 192.168.1.11 "df -h"
xops exec root@192.168.1.11 "uptime"
批量执行:
xops exec --host host1,host2 -c "uptime"
xops exec --host host1 -- uptime
xops exec --tag web -c "uptime"
xops exec -I hosts.txt --shell script.sh
xops exec --tag web --shell script.sh -- arg1 "arg 2"
连接目标语义说明:
显式指定的 user 和 port 优先完整匹配,自动复用已有 Host 并严格隔离 Identity,与 ssh/sftp/scp 行为一致。
跳板机(-J/ProxyJump)解析策略:优先匹配已有 Node、Alias 或 ~/.ssh/config Host;直连跳板明确要求使用 Node/Alias、FQDN、IP 或 host:port;未加端口的单标签主机名须先配置为 Node/Alias。
--host、--ifile (-I) 和 --tag 互斥,只能选择一种,再用 --exclude 排除部分目标。
注意事项:
- -x 需要本地终端输入,仅限单主机,不能与 --shell、--stream、--out-dir 组合。
- 脚本和 Unix 提权仅支持 bash/sh/zsh/fish;--no-login 仅用于 Bash。
- 显式非交互执行默认超时 5 分钟,缓冲结果仅保留最后 5 MiB。
Usage:
xops exec [flags] [command] [-- [arg...]]
Flags:
--alias string 连接别名
-c, --cmd string 要执行的命令
--exclude strings 排除指定的主机(支持节点ID/别名/IP/User@Host,逗号分隔或多次指定)
-h, --help help for exec
--host string 目标主机,多个主机用逗号分隔
-i, --identity string SSH 身份(私钥)文件路径
-I, --ifile string 主机列表文件
-x, --interactive 交互模式(支持 tail -f、vim、top 等需要终端的命令,仅限单主机)
--interpreter string 远端执行解释器:server(使用远端默认 Shell)、bash、sh、zsh、fish、powershell、pwsh 或 cmd
-J, --jump string 跳板机地址,支持 Node/Alias、FQDN、IP 或 [user@]host[:port]
--launch-dialect string 服务端启动方言:unknown、posix、fish、powershell 或 cmd;Bash/sh/zsh/fish 要求 posix 或 fish
-l, --login string SSH 登录用户名
--login-shell 启用/关闭显式 Bash/zsh/fish 的登录环境;不能与 server 或 --no-login 组合
--no-login 不加载登陆shell (用于避免欢迎信息/MOTD等干扰)
--otp string 当前连接会话的一次性动态口令 (OTP/2FA)
--otp-stdin 从标准输入安全读取一次性动态口令 (OTP)
--out-dir string 将输出保存到指定目录的按主机命名的日志文件中
--passphrase-stdin 从标准输入 (stdin) 安全读取私钥密码,避免在进程参数中暴露明文
--password-stdin 从标准输入 (stdin) 安全读取密码,避免在进程参数中暴露明文
-p, --port uint16 SSH端口
--remember string 凭据保存策略: ask、always、never;未指定时继承 credential.remember_prompted,再默认 ask;批处理不保存
--shell string 本地Shell脚本文件
--stream 启用实时流式输出 (多主机时自动添加主机前缀)
--sudo 使用sudo执行
--tag string 按分组(标签)执行
--task int 并行执行的主机数 (default 3)
Global Flags:
--color string ANSI 颜色输出 (auto=自动检测管道/重定向, never=禁用, always=强制启用)
--debug 开启调试模式 (等同于 --log-level=debug)
--lang string 界面语言 (zh/en)
--log-level string 设置内部诊断日志级别 (debug, info, warn, error)