Skip to first unread message

davicho rivas

Oct 5, 2022, 11:04:39 PM10/5/22
Hi all,

I am using a script to be able to initialize sessions in secure crt but I have an error when executing the script:

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

crt.Screen.Synchronous = True

Sub Main()

Const ForReading = 1, ForWriting = 2, ForAppending = 8
'To define which line to start
Const StartLine = 1
'To define file system object, and related parameters
'fso, file1 is to define the file system
'line store the information of one NE in one line
'neinfo stores the line into array
'LineIndex store the number of the lines
Dim fso, file1, line, neinfo, LineIndex
'Define the access mode to the routers
Dim to_save, to_conf, to_check

to_check = 1
to_save = 0
to_conf = 0
'open file all.csv, to read line by line later
set fso = CreateObject("Scripting.FileSystemObject")
set file1 = fso.openTextFile("D:\David\Informes_y_Documentos\CLASS\MEMORIES\Data\AutomatizacionSecureCRT\all\all.csv", ForReading, False)

' according to the constant Startline, read the file until the startline
if Startline > 1 then
for LineIndex = 1 to StartLine-1
line = file1.readline
end if

'Read line by line for the document, and for each line, login in the the NE represented and do the related activity
do while file1.AtEndofStream <> True

' read one line
line = file1.readline
LineIndex = LineIndex +1
' Sperate the information and put into an array NeInfo
NeInfo = split (line, ",")

crt.Screen.WaitForString "#"

' login to the device use ssh or telnet, the command line is different
if NEInfo(3) = "ssh" then
crt.Screen.Send NeInfo(3) & " " & NeInfo(4) & "@" & NeInfo(2) & vbCr
crt.Screen.Send NeInfo(3) & " " & NeInfo(2) & vbCr
crt.Screen.WaitForString "sername:"
crt.Screen.Send NeInfo(4) & vbCr
end if

' If the router is login for the first time, the solaris system need to confirm to save the password information. Here to judge.
Dim SwitchKey


Select case SwitchKey
case 1
crt.Screen.Send "yes" & vbCr
crt.Screen.WaitForString "assword:"
crt.Screen.Send NEinfo(5) & vbCr

case 2
crt.Screen.Send NEinfo(5) & vbCr
End Select

'To find out the router name for future use
dim strResult, strline
strResult = crt.Screen.ReadString (">")
strline = split (strResult, "<")

' Temporarily not pause screen
crt.screen.send "screen 0 temp" & vbCr

if to_check = 1 then
'crt.Screen.WaitForStrING ">"
crt.Screen.WaitForStrING Strline(1) & ">"
crt.Screen.Send "display clock" & vbCr
end if

if to_conf = 1 then
'crt.Screen.WaitForStrING ">"
crt.Screen.WaitForStrING Strline(1) & ">"
crt.screen.send "" & vbCr
crt.Screen.WaitForStrING Strline(1) & ">"
crt.screen.send "system-view" & vbCr
crt.Screen.WaitForStrING "]"
crt.Screen.Send "dis this" & vbCr

crt.Screen.WaitForStrING "]"
crt.Screen.Send "return" & vbCr
end if

if to_save = 1 then
crt.Screen.WaitForStrING ">"
crt.Screen.Send "save" & vbCr
crt.Screen.WaitForStrING "[Y/N]"
crt.Screen.Send "y" & vbCr
end if

crt.Screen.WaitForStrING Strline(1) & ">"
crt.Screen.Send "quit" & vbCr

' one router completed, continue to next router until file empty
end sub

The error tells me that there is an invalid character on line 9, but I search and can't find the error, can you help me please
Reply all
Reply to author
0 new messages