SecureCRT 在 Debian 上的自定义脚本支持与实现
脚本支持概览
内置脚本快速上手 Python 示例
# $language = "python"
# $interface = "1.0"
import time
user = 'admin'
passwd = 'YourPassword' # 建议改为密钥或更安全的方式
def log_name():
return time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime())
def main():
crt.Screen.Synchronous = True
with open('ip.txt') as f:
hosts = [line.strip().split()[0] for line in f if line.strip()]
for ip in hosts:
# 可根据实际设备调整参数,示例为通用 SSH 连接
cmd = f"/SSH2 /L {user} /PASSWORD {passwd} /C 3DES /M MD5 {ip}"
crt.Session.ConnectInTab(cmd)
time.sleep(1)
crt.Screen.Send('\r')
crt.Screen.WaitForString('>')
ts = log_name()
crt.Session.LogFileName = f"{ts}_{ip}.log"
crt.Session.Log(True)
crt.Screen.Send('uname -a\r')
crt.Screen.WaitForString('>')
crt.Screen.Send('uptime\r')
crt.Screen.WaitForString('>')
# 断开当前标签页
crt.Session.Disconnect()
会话登录动作与简单自动化
命令行与 Expect 的外部自动化
#!/usr/bin/expect -f
set timeout 20
set session [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set command [lindex $argv 3]
spawn securecrt -ssh $username@$session -password $password
send "$command\r"
expect eof
安全与排错建议