利用vbs脚本通过secureCRT远程登录来批量备份网络设备脚本
使用:打开secureCRT然后选择脚本,运行此脚本就可
此脚本调用e:/设备备份/ip.txt文件,此文件内格式:ip地址 用户名 密码 设备名
#$language = "VBScript" #$interface = "1.0" crt.Screen.Synchronous = True Sub Main Const ForReading = 1 ForWriting = 2 ForAppending = 8 Dim wordkey Dim fso Dim file1 Dim line Dim params Set fso = CreateObject("Scripting.FileSystemObject") Set file1=fso.OpenTextFile("e:\设备备份\ip.txt",ForReading,False) ‘文件格式:ip 用户名 密码 设备名 While file1.AtEndOfStream <> True ‘逐行读取该文件 line = file1.ReadLine params = Split (line) crt.Session.Connect "/telnet" & " " & params(0) ‘等效 telnet ip地址 23 crt.Session.LogFileName = "e:/设备备份/" + params(3) + Replace(Replace(Replace(date, ":", ""), "/", ""), " ", "") + "_log.txt" crt.Session.Log True wordkey = crt.Screen.WaitForStrings ("username:","login:","Username:",3) ‘3秒内根据登录提示来选择 Select case wordkey case 1 crt.Screen.Send params(1) & chr(13) crt.Screen.WaitForString "PASSCODE:" crt.Screen.Send params(2) & chr(13) crt.Screen.WaitForString "#" crt.Screen.Send "show run" & chr(13) While (crt.Screen.WaitForString("--More--",3)= true) crt.Screen.Send " " wend case 2 crt.Screen.Send params(1) & chr(13) crt.Screen.WaitForString "Password: " crt.Screen.Send params(2) & chr(13) crt.Screen.WaitForString ">" crt.Screen.Send "dis cu" & chr(13) While (crt.Screen.WaitForString("---- More ----",3)= true) crt.Screen.Send " " wend case 3 crt.Screen.Send params(1) & chr(13) crt.Screen.WaitForString "Password:" crt.Screen.Send params(2) & chr(13) crt.Screen.WaitForString ">" crt.Screen.Send "dis cu" & chr(13) While (crt.Screen.WaitForString("---- More ----",3)= true) crt.Screen.Send " " wend End Select crt.Session.Disconnect wend crt.Screen.Synchronous = False End Sub
原文地址:http://sw5720.blog.51cto.com/8812314/1617863