CRT脚本登录设备备份

使用CRT,运行脚本,备份Cisco设备配置文件:
脚本如下:

# $language = "VBScript"
# $interface = "1.0"

Sub Main
     Const ForReading = 1, ForWriting = 2, ForAppending = 8
     Dim fso,file1,line,str1,str2,params,host,passwd,user
     Set fso = CreateObject("Scripting.FileSystemObject")
     Set file1 = fso.OpenTextFile("D:\Script\ip.txt",Forreading, False)       
     crt.Screen.Synchronous = True
     DO While file1.AtEndOfStream <> True
        line = file1.ReadLine
        params = Split (line)
        host = params(0)
        user = params(1)
        passwd = params(2)
        cmd = "/SSH2 /L " & user & " /PASSWORD " & passwd & " /C 3DES /M MD5 " & host
        crt.Session.Connect cmd
        crt.session.LogFileName = "D:\Script\log\" & params(0) & ".txt"
        crt.session.Log(true)
        crt.Screen.waitForString "#"
        str1 = "sh cdp nei"
        crt.Screen.Send str1 & vbcr
        crt.Screen.Send "                                                " & vbcr
        str2 = "sh run"
        crt.Screen.Send str2 & vbcr
        crt.Screen.WaitForString " --More-- "
        crt.Screen.Send "                                                " & vbcr
        crt.Screen.Send "                                                " & vbcr
        crt.Screen.waitForString "end"
        crt.Screen.waitForString "#"
        crt.Screen.Send "exit" & vbcr
        crt.Session.Disconnect        
  loop
     crt.Screen.Synchronous = False      

End Sub

ip.txt文档如下:

192.168.2.1 Cisco Cisco@123
192.168.2.2 Cisco Cisco@123
posted @ 2020-09-25 09:22  Ant·Hanks  阅读(580)  评论(0)    收藏  举报