VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   Error detecting in loop (https://forums.vandyke.com/showthread.php?t=14437)

HappyHouse 02-20-2021 06:40 AM

Error detecting in loop
 
Hello VanDyke team,

Im a rookie in scripting an need help.
Ive a small VBA Script using a loop to connect to several routers to request several coomands. This works fine. But sometimes a router is not reachable. in this case the loop stops with an error. What I need is that my script detects the problem (router not reachable) and go on with the next router in list.

Code:

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

crt.Screen.Synchronous = True

Sub Main

Dim objFileToRead, fileLocation, strLine, counter1

fileLocation = crt.Dialog.FileOpenDialog("Choose file")

Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile(fileLocation,1)

do while not objFileToRead.AtEndOfStream

strLine = objFileToRead.ReadLine()

        crt.Screen.Send "login " & strline & chr(13)
        crt.Screen.WaitForString "Password for xxxxxx: "
        crt.Screen.Send "xxxxxxxx" & chr(13)
        crt.Sleep(3000)
        crt.Screen.WaitForString strline
        crt.Screen.Send "sh ver " & chr(124) & " i uptime" & chr(124) & "System image" & chr(13)
        crt.Screen.WaitForString strline
        crt.Screen.Send "exit" & chr(13)
    crt.Screen.WaitForString "INFO:    Session closed", "2"

loop

objFileToRead.Close

Set objFileToRead = Nothing
crt.Dialog.MessageBox("Done !!")

End Sub


bgagnon 02-22-2021 08:42 AM

Hi HappyHouse,

That's more a scripting language question than it is SecureCRT, but I will try to help. :)

The error handling mechanism in VBScript (which SecureCRT supports, not VBA, which is different) is the On Error Resume Next construct. The scripting manual has some info about using this mechanism in Chapter 3.6 Handling Connection Failures Within a Script.

The task you are trying to accomplish sounds really close to what is exemplified in this example script.

bgagnon 02-22-2021 09:46 AM

Hi HappyHouse,

A colleague pointed out an optional parameter to Connect() method that might help you out, the bSuppressErrorPopups parameter.

Quote:

The Connect method also takes an optional parameter (True or False) that specifies whether or not to suppress pop-up messages. This parameter defaults to False (don't suppress).
VBScript Syntax:
object.Connect [strConnectInfo [, bWaitForAuthToComplete [, bSuppressErrorPopups]]]


HappyHouse 02-22-2021 12:51 PM

Hello Brenda,

thanks for quick response. Sorry for my imperfect wording, I meant VBScript.
Thanks also for your help for an issue a little bit outside of SecureCRT :)
The scripting manual was helpful after trying the examples several times with a few reconfigurations.
The further tips I will try soon.


All times are GMT -6. The time now is 04:48 AM.