温馨提示×

ubuntu securecrt怎么批量操作

小樊
52
2026-10-09 22:39:43
栏目: 智能运维

在 Ubuntu 下使用 SecureCRT 进行批量操作(同时向多个会话发送命令),常用以下几种方法:


一、使用「聊天室(Chat Window)」批量发送(最常用)

步骤

  1. 打开多个 SecureCRT 会话(如多台服务器)
  2. 菜单:View → Chat Window(显示聊天窗口)
  3. 在聊天窗口中:
    • 右键 → Send Chat to All Sessions
    • 或点击工具栏的 “发送到所有会话” 图标
  4. 在输入框中输入命令,回车即可 同时发送到所有会话

✅ 适合:

  • 批量执行 uptime、df -h、tail log
  • 同时重启服务

⚠ 注意:

  • 所有会话都会收到相同命令
  • 不适合需要交互的输入(如 sudo 密码)

二、使用「命令管理器 / 脚本」批量操作(推荐自动化)

1️⃣ 使用 SecureCRT 脚本(VBScript / Python)

SecureCRT 支持脚本,适合复杂批量任务。

示例(Python 脚本):

# $language = "Python"
# $interface = "1.0"

for session in crt.Session:
    crt.Session.Connect("/SSH2 user@host")
    crt.Screen.Send("uptime\r")

或者使用现成脚本遍历多个主机。


三、使用「标签组(Tab Group)」批量发送

  1. 将多个会话放在 同一个 Tab Group
  2. 右键标签 → Send Commands to Tab Group
  3. 输入命令即可

✅ 比“所有会话”更可控


四、使用「按钮栏(Button Bar)」批量执行

  1. View → Button Bar
  2. 新建按钮
  3. 设置:
    • Function: Send String
    • String: sudo systemctl restart nginx\r
  4. 勾选 Send to all sessions

✅ 适合固定常用命令


五、Ubuntu 下替代方案(更推荐运维)

如果你经常批量操作,SecureCRT 不是唯一选择:

  • pssh(Parallel SSH)
    pssh -h hosts.txt -i "uptime"
    
  • tmux + synchronize-panes
  • Ansible

总结建议

场景 推荐方式
临时批量执行 Chat Window
指定一组服务器 Tab Group
固定命令 Button Bar
自动化运维 脚本 / pssh / Ansible

如果你是 特定场景(如批量改配置、批量传文件),可以告诉我,我给你具体方案。

0 踩