Cisco Router Batch Collection of Information

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

crt.Screen.Synchronous = True

' This automatically generated script may need to be
' edited in order to work correctly.

Sub Main

 Const ForReading = 1, ForWriting =2, ForAppending = 8, StartLine = 1
 Dim fso_NEList
 Dim file_NEList, NERecord, LineIndex, i, j
 Dim CurrentTime, OutputFileName
 Dim xlsAppCmdLst,xlsAppNEList,xlsWorkBook,xlsSheet
 Dim iCmdRowCount, iNERowCount, strCmd(1000,2), strNE(60000,6)
 Dim FileName, objDialog
 Dim test
 
 test = 1

 CurrentTime = replace (Now(),":","-")
 CurrentTime = replace (CurrentTime,"/","-")

 crt.Screen.Send "date" & vbCr
 crt.Screen.WaitforString "$"
 crt.Screen.Send "echo Start Reading data Files, please wait..." & vbCR
 crt.Screen.WaitforString "$"
 
 Set xlsAppCmdLst = CreateObject("Excel.Application") ' create Excel object
' xlsAppCmdLst.Visible = True 'true to display, false to not display
 Set xlsWorkBook = xlsAppCmdLst.Workbooks.Open ("D:\Scripts\input\command-check.xlsx") 'Open excel of commands
 Set xlsSheet = xlsWorkBook.Sheets("sheet1")

 iCmdRowCount = xlsSheet.usedRange.Rows.Count-1 'get the row number
 For i = 1 To iCmdRowCount
  strCmd (i,1) = xlsSheet.Cells(i+1,1) 
  strCmd (i,2) = xlsSheet.Cells(i+1,2) 
 Next

 xlsWorkBook.Close
 xlsAppCmdLst.Quit
 Set xlsAppCmdLst = Nothing
 Set xlsWorkBook = Nothing 
 Set xlsAppCmdLst = Nothing

 Set xlsAppNELst = CreateObject("Excel.Application") 
 'xlsAppNELst.Visible = True 
 Set xlsWorkBook = xlsAppNELst.Workbooks.Open ("D:\Scripts\input\NEList.xlsx") 
 Set xlsSheet = xlsWorkBook.Sheets("sheet1")

 iNERowCount = xlsSheet.usedRange.Rows.Count - 1 
 iNEColumnCount = xlsSheet.usedRange.Columns.Count

 For i = 1 to iNERowCount
  For j = 1 to iNEColumnCount
   strNE(i,j) = xlsSheet.Cells(i+1,j) 
  next
 Next
 
 'xlsWorkBook.Save
 xlsWorkBook.Close
 xlsAppNELst.Quit
 Set xlsAppNELst = Nothing 
 Set xlsWorkBook = Nothing 
 Set xlsAppNELst = Nothing 
 
 crt.Screen.Send "date" & vbCr
 crt.Screen.WaitForString "$"
 crt.Screen.Send "echo Completed the loading, begin to collect information" & vbCR
 
 If test = 1 then
'   exit sub
 end if
 
 for i = Startline to iNERowCount
  
  crt.Screen.WaitForString "$"

  if strNE(i,4) = "ssh" then
   crt.Screen.Send strNE(i,4) & " " & strNE(i,5) & "@" & strNE(i,3) & vbCr
  else
   crt.Screen.Send strNE(i,4) & " " & strNE(i,3) & vbCr
   crt.Screen.WaitForString "sername:"
   crt.Screen.Send strNE(i,5) & vbCr
  end if

  Dim SwitchKey

  SwitchKey=crt.Screen.WaitForStrings("(yes/no)?","assword:",60)

  Select case SwitchKey
   case 1

    crt.Screen.Send "yes" & vbCr
    crt.Screen.WaitForString "assword:"
    crt.Screen.Send strNE(i,6) & vbCr

   case 2

    crt.Screen.Send strNE(i,6) & vbCr

  End Select

  dim strResult, strline
  strResult = crt.Screen.ReadString ("#")
  strline = split (strResult, "#")

  crt.screen.send vbCr
  
  for j = 1 to iCmdRowCount

   If crt.Session.Logging Then
    crt.Session.Log False
   End If

   crt.Screen.WaitForString Strline(0) & "#"

   LineIndex = j
   if strCmd(j,2)="" then
    strCmd(j,2)=".txt"
   end if
   
   OutputFileName = "d:\Scripts\Result\Output\" & CurrentTime & "\" &  LineIndex & "." & strCmd(j,1) & "\" & strNE(i,3) & "-" & Strline(0) & strCmd(j,2)
'   OutputFileName = "d:\Scripts\Result\Output\" & CurrentTime & "\" &  LineIndex & "." & strCmd(j,1) & "\" & strCmd(j,1) & "-" & strNE(i,3) & "-" & Strline(0) & strCmd(j,2)
   OutputFileName = Replace (OutputFileName, " ","_")
   OutputFileName = Replace (OutputFileName, "|", "_")
   OutputFileName = Replace (OutputFileName, "/", "_")
   crt.Session.LogFileName = OutputFileName
   crt.Session.LogUsingSessionOptions

   crt.Screen.Send strCmd (j,1) & vbCr
   Do
    strResult = crt.Screen.ReadString ("---- More ----",Strline(0) & "#")
    if crt.Screen.MatchIndex = 1 then crt.Screen.Send " "
    if crt.Screen.MatchIndex = 2 then
     crt.Screen.Send vbCr
     Exit Do
    end if
   loop

   crt.Session.Log False
  next

  crt.Screen.WaitForStrING  Strline(0) & "#"
  crt.Screen.Send "exit" & vbCr
 next
 
 ' Return the original log
 crt.Session.LogFileName = "D:\Daily\CRT\%Y\%M\%M-%D\%Y%M%D-%h-%m-%s-%S.LOG"
 ' Turn on log session
 crt.Session.LogUsingSessionOptions
end sub

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值