关闭

crt应用脚本一例子,windows下的expect

2272人阅读 评论(0) 收藏 举报

日常工作有大量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    

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:3649356次
    • 积分:59815
    • 等级:
    • 排名:第40名
    • 原创:1549篇
    • 转载:1252篇
    • 译文:0篇
    • 评论:459条
    最新评论