#$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