日常工作有大量cisco路由器,交换机设备备份,telnet设备需要通过其一台服务器(solaris系统)进入,因网络关系无法通过TFTP完成备份.
因此程序通过crt软件脚本实现.
作:gyhong
# $language = "VBScript"
# $interface = "1.0"
Cnstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb;Persist Security Info=False"
tabname="setmessage"
Set cn=CreateObject("ADODB.Connection")
Set rs=CreateObject("ADODB.Recordset")
'Dim fso, MyFile
'Set fso = CreateObject("Scripting.FileSystemObject")
'Set MyFile = fso.CreateTextFile("testfile.txt", True)
cn.Open Cnstr
rs.Open "select * from "+tabname,cn,1,3
Dim settype,ipaddr,seten1,seten2,filename
While Not rs.eof
settype=rs("settype")
ipaddr=rs("ipaddr")
seten1=rs("en1")
seten2=rs("en2")
filename=rs("filename")
If settype="a" then
crt.Session.LogFileName = filename
crt.Session.Log True
crt.Session.Connect ("/telnet IP地址")
crt.Screen.WaitForString "login:"
crt.screen.Send "root" & Chr(10)
crt.Screen.WaitForString "assword:"
crt.screen.Send "密码" & Chr(10)
crt.Screen.WaitForString "#"
'登录switch systme
crt.screen.Send "telnet "&ipaddr & Chr(10)
crt.Screen.WaitForString "assword:"
crt.screen.Send seten1 & Chr(10)
crt.Screen.WaitForString ">"
crt.screen.Send "en" & Chr(10)
crt.Screen.WaitForString "assword"
crt.screen.Send seten2 & Chr(10)
' crt.Session.Log True
crt.Screen.WaitForString "#"
crt.screen.Send "show running-config" & Chr(10)
crt.sleep 100
crt.screen.Send Chr(32)
crt.sleep 100
crt.screen.Send Chr(32)
crt.sleep 100
crt.screen.Send Chr(32)
crt.sleep 100
crt.screen.Send Chr(32)
crt.sleep 100
crt.screen.Send Chr(32)
crt.sleep 100
crt.screen.Send Chr(32)
crt.sleep 100
crt.screen.Send Chr(32)
crt.sleep 100
crt.screen.Send Chr(32)
crt.sleep 100
crt.screen.Send Chr(32)
crt.sleep 100
crt.screen.Send Chr(32)
crt.sleep 100
crt.screen.Send Chr(32)
crt.sleep 100
crt.screen.Send Chr(32)
crt.screen.Send Chr(10)
crt.Screen.WaitForString "#"
crt.screen.Send "exit"&Chr(10)
crt.Session.Log False
'退出中转系统
crt.Screen.WaitForString "#"
crt.screen.Send "exit"&Chr(10)
If crt.session.connected Then crt.session.disconnect
End If
rs.movenext
Wend
crt应用脚本一例子,windows下的expect
最新推荐文章于 2021-11-24 10:44:51 发布