SecureCRT脚本实现自动备份华为交换机配置.pdf
下面这个脚本能批量对交换机做配置备份工作,在使用时请根据情况更改脚本中交换机的登
录密码如下位置
crt.Screen.WaitForString
crt.Screen.SendsuVbCr
crt.Screen.WaitForStringPassword:
crt.Screen.SendhuaweiVbCr
crt.Screen.WaitForString
其中,name.txt文件就是一行一个交换机的IP地址,如:
请将下列脚本保存为*.VBS文件
#$language=VBScript
#$interface=1.0
Thisscriptshowshowtoreadinafile,anditdemonstrateshowto
performsomepreprocessingondata(splittingthefiledatainto
separatestrings)beforesendingittoaserver.
ConstantusedbyOpenTextFile()
ConstForReading=1
Submain
Openafile,readitinsenditonelineatatime
Dimfso,f
Setfso=CreateObject(Scripting.FileSystemObject)
Setf=fso.OpenTextFile(d:\name.txt,ForReading,0)
Dimline,params
DoWhilef.AtEndOfStreamTrue
Readeachlineoftheprintersfile.
line=f.Readline
Splitthelineup.Eachlineshouldcontain3space-separatedparameters
params=Split(line)
params(0)holdsparameter1,params(1)holdsparameter2,etc.
Sendmycommandwiththeappendedparametersfromthefilewith
anappendedCR.
crt.Screen.Sendtelnetparams(0)vbC
waitforswitchprompt
crt.Screen.WaitForStringUsername:
crt.Screen.SendadminVbCr
Waitforatringthatlookslikepassword:orPassword:
crt.Screen.WaitForStringPassword:
Sendyourpasswordfollowedbyacarriagereturn
crt.Screen.SendadminVbCr
crt.Screen.WaitForString
crt.Screen.SendsuVbCr
crt.Screen.WaitForStringPassword:
crt.Screen.SendhuaweiVbCr
crt.Screen.WaitForString
executesomecommands
crt.Screen.Sendtftp50putvrpcfg.cfgparams(0).txtVbCr
crt.Screen.SendquitVbCr
leaveoutswitch,stayinlinux
crt.Screen.WaitForString#,3
Causea3-secondpausebetweensendsbywaitingforsomethingunexpected
withatimeoutvalue.
Loop
EndSub