connection state (General questions)
How do I know if a server has timed out?
In my example below when if a server is down the script errors when it hits sshConnection.connect. Is there a way to detect timeout and not connect to that server?
[code]
Option Explicit
Dim sshConnection
Dim mExecuted, gastrDomainName, intIndex, strDomainName, gstrDomainName
Dim strPercentUsed, strPercentUsed2, strFindPercent, strFindPercent2
Set sshConnection = WScript.CreateObject( WeOnlyDo.wodTelnetDLXCom.1 )
strDomainName= myserver1, myserver2
gastrDomainName = Split(strDomainName, , )
For intIndex = 0 To UBound(gastrDomainName)
gstrDomainName = gastrDomainName(intIndex)
sshConnection.Timeout = 10
sshConnection.Protocol = 2
sshConnection.Blocking = 1
sshConnection.Port = 22
sshConnection.HostName = Trim(gstrDomainName)
sshConnection.Login = user1
sshConnection.Password = password1
sshConnection.Connect
WScript.Echo sshConnection.State
sshConnection.WaitFor ( regex:[$ #>:] $ )
sshConnection.DataReady = 0
mExecuted = sshConnection.Execute( df -h / + vbLf, $ )
wscript.echo mExecuted
strFindPercent = ((InStrRev(gstrLogMsg, ,Len(gstrLogMsg))) -3)
strPercentUsed = Trim(Mid(gstrLogMsg,strFindPercent,3))
mExecuted = sshConnection.Execute( df -h /toptech_prj + vbLf, $ )
wscript.echo mExecuted
strFindPercent2 = ((InStrRev(gstrLogMsg2, ,Len(gstrLogMsg2))) -3)
strPercentUsed2 = Trim(Mid(gstrLogMsg2,strFindPercent2,3))
wscript.echo gstrDomainName & : Root Partition: & strPercentUsed & & vbCrLf & /toptech_prj: & strPercentUsed2 & & vbCrLf
sshConnection.Disconnect
Next
Set sshConnection = Nothing[/code]
Re: connection state
Hi Kevin,
Using Connect Method wodTelnetDLX connects to server. Without calling Connect Method you cannot detect connect errors.
In scripting environments like VBS commands are executed line by line. If some error occur component will return it immediately.
However you can use On Error Resume Next statement and receive error (if there is any) after Connect Method using wodTelnetDLX LastError and ErrorText Property.
[code]...
telnet.Connect
If telnet.LastError <> 0 Then
MsgBox telnet.ErrorText(telnet.LastError)
End If[/code]
If I maybe misunderstand your question can you maybe explain it little bit more and we will try to help you.
Regards,
Drazen