VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   Broken pipe error (https://forums.vandyke.com/showthread.php?t=12097)

etalkishere 09-13-2015 10:34 AM

Broken pipe error
 
Is there a crt error message that my vbscript code can catch
And act on it accordingly?

Thanks.

rtb 09-14-2015 09:17 AM

Hi Peter,

VBScript error handling is enabled via On Error Resume Next. It is disabled via On Error Goto 0.

You should limit the scope of error handling so you don't mask errors that you need to know are happening.

Here is an example of scoping error handling to a connection attempt:
Code:

strErr = ""
nError = 0
On Error Resume Next
    crt.Session.Connect("/SSH2 /L " & SSHUser & " /password " & SSHPW & " " & IpAdd)   
    strErr = Err.Description
    nError = Err.Number
On Error Goto 0
If nError <> 0 Then
    ' Handle error
    Err.Clear
Else
    ' Do work
End If

Does this help?

etalkishere 09-14-2015 10:07 AM

Thanks Tod for the response.

I guess the issue I am having is, the "broken pipe" error can happen anywhere in my code which deals with client (my script) and server (a router) interaction.

For example, my script sends a command to the router, gets some information for further processing. During this client/server interaction, broken pipe error pops up randomly, not just at one particularly place in my code.

So, would your error handling code that you share help my case? If so, where would i place your code to catch random nature of 'broken pipe" error messages, ie, beginning of my code once?

rtb 09-14-2015 10:34 AM

Hi Peter,

You can modify the code example that I provided to work with the Send() and WaitForString() methods, but that will expand your code unnecessarily. You may consider moving the Send() and WaitForString() methods into functions. Here are a couple of example functions:
Code:

Set g_objTab = crt.GetScriptTab
Set g_fso = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Set g_objErrLog = g_fso.OpenTextFile("C:\Documents and Settings\vdt-csg\Desktop\" & g_objTab.Caption & ".Err.log", ForWriting, True)

Send("ls" & vbcr)
Wait("#")

Function Send(strString)
    Send = True
    On Error Resume Next
    g_objTab.Screen.Send strString
    nError = Err.Number
    strError = Err.Description
    On Error Goto 0
    If nError <> 0 Then
        g_objErrLog.Write "SEND error(" & nError & "): " & strError & vbcrlf
        Send = False
        Exit Function
    End If
End Function

Function Wait(strString)
    Wait = True
    On Error Resume Next
    g_objTab.Screen.WaitForString strString
    nError = Err.Number
    strError = Err.Description
    On Error Goto 0
    If nError <> 0 Then
        g_objErrLog.Write "WAIT error(" & nError & "): " & strError & vbcrlf
        Wait = False
        Exit Function
    End If
End Function


etalkishere 09-19-2015 07:45 AM

Hi Todd,

Thanks for the sample code. I tried it (replacing all .send and .waitforstring to send() and wait() functions), but unfortunately, the code didn't catch the broken pipe error :( Here is actual output. As you can see, once the bp issue happened, my vbscript continued to send the next command ("term length 0"). There was no error message written to the error log file.

router#ssh 112.250.224.4
CCC
*************************************************************
* *
* W A R N I N G *
* *
* The system to which you have connected is proprietary *
* and confidential. Unauthorized access is prohibited and *
* violators may be prosecuted. Your actions on this system *
* may be subject to monitoring and continued use of the *
* system constitutes permission for such monitoring. *
* *
*************************************************************
Write failed: Broken pipe
[jumpbox]$ term length 0
-bash: term: command not found

rtb 09-21-2015 11:30 AM

Hi Peter,

Thanks for the update and output. I didn't realize where the error was occurring. Script language error handling is intended to handle errors that are local. The error you are seeing is not a local error. It is an error on a remote system, and SecureCRT has no knowledge of the error.

To handle this problem, you will need to create a solution that sends a command, then enters a Do...Loop and handles all possible responses using WaitForStrings() rather than WaitForString().

Here is an example of this concept that might help you create your own solution:
https://forums.vandyke.com/showthrea...7087#post37087
The lines that may help are 108 to 172.

Does this help you create your own scripting solution for the remote errors?


All times are GMT -6. The time now is 03:00 PM.