Skip to content

xops exec

以下列出命令用法和可用选项。已安装版本支持的参数以 --help 为准。

text
对一个或多个远程主机执行命令。支持批量执行和提权。

用法示例(兼容 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 --tag web -c "uptime"
  xops exec -I hosts.txt --shell script.sh

连接目标语义说明:
  显式指定的 user 和 port 优先完整匹配,自动复用已有 Host 并严格隔离 Identity,与 ssh/sftp/scp 行为一致。
  跳板机(-J/ProxyJump)解析策略:优先匹配已有 Node、Alias 或 ~/.ssh/config Host;直连跳板明确要求使用 Node/Alias、FQDN、IP 或 host:port;未加端口的单标签主机名须先配置为 Node/Alias。
  使用 --tag 时会忽略其他主机指定方式。

Usage:
  xops exec [flags] [command]

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 等需要终端的命令,仅限单主机)
  -J, --jump string         跳板机地址,支持 Node/Alias、FQDN、IP 或 [user@]host[:port]
  -l, --login string        SSH 登录用户名
      --no-login            不加载登陆shell (用于避免欢迎信息/MOTD等干扰)
      --out-dir string      将输出保存到指定目录的按主机命名的日志文件中
      --passphrase string   SSH 私钥密码短语
      --passphrase-stdin    从标准输入 (stdin) 安全读取私钥密码,避免在进程参数中暴露明文
      --password string     SSH密码
      --password-stdin      从标准输入 (stdin) 安全读取密码,避免在进程参数中暴露明文
  -p, --port uint16         SSH端口
      --remember string     凭据保存策略: ask、always、never;未指定时继承 credential.remember_prompted,再默认 ask;批处理不保存
      --shell string        本地Shell脚本文件
      --stream              启用实时流式输出 (多主机时自动添加主机前缀)
      --suPwd string        su切换root的密码
      --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)

MIT License