J
jay
Believe it or not...I am new to this side of development. I will try
to provide a little background on this app...I am calling this from an
aspx page. Feeding in the params and basically hoping to go out to the
servers specified in the xml files, run the command that I passed in
and return the output from the server. I was able to make this work
with a single thread and a single server. Now...it is time to beef it
up a bit...and multi-thread it. I haven't messed with threading much
in the past...and I am sure that someone will respond with "learn to
crawl before you learn to run." If life were that simple...
I continue to get the Object reference not set error when I call this
dll. It compiles fine...but, something is obviously not initializing
properly...and I am just missing it. I wrote a quick test function and
put it in the sshSearch Class and it worked fine...shich means that the
SearchNet function is NOT working fine. I would really appreciate ANY
help that ANYONE can provide. I have been researching this for about 2
weeks...including the purchase of a new book (dang things are
expensive) and just about every group that I can find.
Again...thanks!!! Jay
Imports System
Imports System.IO
Imports System.Web
Imports System.Xml
Imports System.Text
Imports System.Data
Imports System.Threading
Imports System.Diagnostics
Imports Microsoft.VisualBasic
Namespace SearchThis
Public Class sshSearch
Public allResults As String
Public strNow As String
Public Function SearchNet( strSearch As String,intLogLevel As Integer )
Dim dtmNow As DateTime
dtmNow = DateTime.Now()
strNow = dtmNow.ToString("MMddyyyyhhmmss")
Dim usrname As String
usrname = "username"
Dim pw As String
pw = "password"
Dim cfg As New XmlDataDocument
Dim strServerGroup As String
strServerGroup = "cbaa"
If strServerGroup = "cbaa" Then
cfg.Load( "d:\inetpub\wwwroot\HAT\bin\searchnet" & strServerGroup &
".config" )
End If
Dim ndList As XmlNodeList
ndList = cfg.SelectNodes("//ServerMenuItemIpAddress")
Dim nd As XmlNode
Dim i As Integer
Dim s(32) As ThreadData
Dim t As Thread
i = 0
For Each nd in ndList
Dim serverIpAddress As String
serverIpAddress = nd.InnerText
Dim strPlinkArguments As String
strPlinkArguments = "-ssh -l " & usrname & " -pw " & pw & " " &
usrname & "@" & serverIpAddress & " -batch " & strSearch
s(i) = New ThreadData
s(i).strPlinkArguments = strPlinkArguments
t = New Thread(AddressOf s(i).DoTheWork)
t.Start()
i = i + 1
Next
Dim j As Integer
Dim allDone as Boolean
Do Until allDone
allDone = True
For j = 0 to i - 1
allDone = allDone And s(i).Done
Next
Loop
For j = 0 to i - 1
allResults = allResults + s(j).GetResults
Next
If intLogLevel = 1 Then
Dim sw As New
StreamWriter("D:\inetpub\wwwroot\HAT\searchnetlogs\searchnet" & strNow
& ".txt")
sw.write(allResults)
sw.Close()
End If
Return allResults
End Function
End Class
Public Class ThreadData
Public strPlinkArguments As String
Public Done As Boolean
Public searchText As String
Public Sub DoTheWork()
Dim sr As StreamReader
Dim sb As New StringBuilder("")
Dim input As Integer
Dim proc As Process = New Process()
proc.StartInfo.FileName = "d:\inetpub\wwwroot\HAT\bin\plink.exe"
proc.StartInfo.Arguments = strPlinkArguments
proc.StartInfo.UseShellExecute = False
proc.StartInfo.RedirectStandardOutput = True
proc.Start()
sr = proc.StandardOutput
input = sr.Read
Do Until input = -1
sb.Append(ChrW(input))
input = sr.Read
Loop
searchText = sb.ToString
sr.Close()
proc.Close()
Done = True
End Sub
Public Function GetResults()
Return searchText
End Function
End Class
End Namespace
to provide a little background on this app...I am calling this from an
aspx page. Feeding in the params and basically hoping to go out to the
servers specified in the xml files, run the command that I passed in
and return the output from the server. I was able to make this work
with a single thread and a single server. Now...it is time to beef it
up a bit...and multi-thread it. I haven't messed with threading much
in the past...and I am sure that someone will respond with "learn to
crawl before you learn to run." If life were that simple...
I continue to get the Object reference not set error when I call this
dll. It compiles fine...but, something is obviously not initializing
properly...and I am just missing it. I wrote a quick test function and
put it in the sshSearch Class and it worked fine...shich means that the
SearchNet function is NOT working fine. I would really appreciate ANY
help that ANYONE can provide. I have been researching this for about 2
weeks...including the purchase of a new book (dang things are
expensive) and just about every group that I can find.
Again...thanks!!! Jay
Imports System
Imports System.IO
Imports System.Web
Imports System.Xml
Imports System.Text
Imports System.Data
Imports System.Threading
Imports System.Diagnostics
Imports Microsoft.VisualBasic
Namespace SearchThis
Public Class sshSearch
Public allResults As String
Public strNow As String
Public Function SearchNet( strSearch As String,intLogLevel As Integer )
Dim dtmNow As DateTime
dtmNow = DateTime.Now()
strNow = dtmNow.ToString("MMddyyyyhhmmss")
Dim usrname As String
usrname = "username"
Dim pw As String
pw = "password"
Dim cfg As New XmlDataDocument
Dim strServerGroup As String
strServerGroup = "cbaa"
If strServerGroup = "cbaa" Then
cfg.Load( "d:\inetpub\wwwroot\HAT\bin\searchnet" & strServerGroup &
".config" )
End If
Dim ndList As XmlNodeList
ndList = cfg.SelectNodes("//ServerMenuItemIpAddress")
Dim nd As XmlNode
Dim i As Integer
Dim s(32) As ThreadData
Dim t As Thread
i = 0
For Each nd in ndList
Dim serverIpAddress As String
serverIpAddress = nd.InnerText
Dim strPlinkArguments As String
strPlinkArguments = "-ssh -l " & usrname & " -pw " & pw & " " &
usrname & "@" & serverIpAddress & " -batch " & strSearch
s(i) = New ThreadData
s(i).strPlinkArguments = strPlinkArguments
t = New Thread(AddressOf s(i).DoTheWork)
t.Start()
i = i + 1
Next
Dim j As Integer
Dim allDone as Boolean
Do Until allDone
allDone = True
For j = 0 to i - 1
allDone = allDone And s(i).Done
Next
Loop
For j = 0 to i - 1
allResults = allResults + s(j).GetResults
Next
If intLogLevel = 1 Then
Dim sw As New
StreamWriter("D:\inetpub\wwwroot\HAT\searchnetlogs\searchnet" & strNow
& ".txt")
sw.write(allResults)
sw.Close()
End If
Return allResults
End Function
End Class
Public Class ThreadData
Public strPlinkArguments As String
Public Done As Boolean
Public searchText As String
Public Sub DoTheWork()
Dim sr As StreamReader
Dim sb As New StringBuilder("")
Dim input As Integer
Dim proc As Process = New Process()
proc.StartInfo.FileName = "d:\inetpub\wwwroot\HAT\bin\plink.exe"
proc.StartInfo.Arguments = strPlinkArguments
proc.StartInfo.UseShellExecute = False
proc.StartInfo.RedirectStandardOutput = True
proc.Start()
sr = proc.StandardOutput
input = sr.Read
Do Until input = -1
sb.Append(ChrW(input))
input = sr.Read
Loop
searchText = sb.ToString
sr.Close()
proc.Close()
Done = True
End Sub
Public Function GetResults()
Return searchText
End Function
End Class
End Namespace