Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-13-2015, 10:34 AM
etalkishere etalkishere is offline
Registered User
 
Join Date: Sep 2015
Posts: 12
Broken pipe error

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

Thanks.
Reply With Quote
  #2  
Old 09-14-2015, 09:17 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
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?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #3  
Old 09-14-2015, 10:07 AM
etalkishere etalkishere is offline
Registered User
 
Join Date: Sep 2015
Posts: 12
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?
Reply With Quote
  #4  
Old 09-14-2015, 10:34 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
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
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #5  
Old 09-19-2015, 07:45 AM
etalkishere etalkishere is offline
Registered User
 
Join Date: Sep 2015
Posts: 12
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
Reply With Quote
  #6  
Old 09-21-2015, 11:30 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
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?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 05:57 AM.