PDA

View Full Version : Down Devices


walkerte
09-04-2007, 12:44 PM
I'm creating a script that connects to all our routers and copies the runnning config to our tftp server. The script pulls the ip of the device from a .txt file.

The only issue I have sofar is that if the device is unavailable I recieve the following error and it stops the srcipt from continuing:

Error: Connection Failed
File: C:\scripts\CopyRunTFTP.vbs
Line: 49

Is there a way to add error checking for down devices?


Tom

miked
09-04-2007, 05:15 PM
Hello Tom,

Since you're using VBScript, you can use On Error Resume Next to trap the error. You would still need to handle the error as appropriate (for example, On Error Goto 0), but your script shouldn't quit on you the way it currently does.

Here is a short example of a script you would run from within SecureCRT:

#$Language="VBScript"
#$Interface="1.0"
' Connect-DetectErrorConnecting.vbs

Dim g_szError

Sub Main()

Dim nResult, szConnectInfo

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~
' Example of host not found
szConnectInfo = "/TELNET host_not_found"
nResult = Connect(szConnectInfo)
if nResult <> 0 then
MsgBox "Error connecting with info: " & szConnectInfo & _
vbcrlf & vbcrlf & g_szError
else
MsgBox "Connect was successful."
' do some more work
' . . .

crt.Session.Disconnect
end if

End Sub

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function Connect(szConnectInfo)
' Workaround that uses "On Error Resume Next" VBScript directive to detect
' Errors that might occur from the crt.Session.Connect call and instead of
' closing the script, allow for error handling within the script as the
' script author desires.
On Error Resume Next

g_szError = ""
Err.Clear
crt.Session.Connect szConnectInfo
Connect = Err.Number
if Err.Number <> 0 then
g_szError = Err.Description
end if

On Error Goto 0
End Function
Based on this example, do you think On Error Resume Next will help you?