Solved

pulling info from a text file

Posted on 2003-10-28
10
235 Views
Last Modified: 2010-04-17
Hello all
I am trying to write a script that will execute a command on a server using Wshell.run piping it to a text file then reading the text file. Compare the output of the text file to a table in a database if they are not the same pull it out of one table and insert it into another table.

Hoe do I go about reading the text file and setting variables for it

The text file looks like the below
SESSIONNAME           CLIENTNAME          TRANSPORT  ADDRESS
console                        0                        Conn              wdcon
ica-tcp                        65536                    Listen          wdica
rdp-tcp                       65537                   Listen            rdpwd
>ica-tcp#37             magnus.hjorleifsson    5                 Active rdpwd
                                                                  3                  Idle
                                                                 2                    Idle            

I need to pull any instance of ica-tcp#xx along with the username and compare that with a table to see if the ica-tcp#xx and username match the text fileresults if so do nothing else run something

Thanks in advance
Magnus
0
Comment
Question by:magsdtev
  • 3
  • 3
10 Comments
 
LVL 3

Expert Comment

by:monkesdb
ID: 9635769
a simple solution is as follows

*UNTESTED*

#include <vector>
#include <string>

typedef struct tag_details {
  string session_name;
  string client_name;
  string transport;
  string address
} details;


...

vector<details> info;
#define i   info.size() - 1       //I agree this is not fastest but it's easier to understand the code

fstream theFile("TheFile.txt");

while(!theFile.eof() && !theFile.fail())
{
  info.push_back(details());
  theFile >> info[i].session_name >> info[i].client_name >> info[i].transport >> info[i].address
}

if( theFile.fail() )
 // file not properly formatted.

#undef i

...

that should fill 'info' with all the information from the file you can then access it using

info[record_number].field;

remember that record 0 will contain the top line which are only labels so start at 1.
0
 
LVL 3

Expert Comment

by:monkesdb
ID: 9638654
oh, and don't forget (like i did) to close the file when you're finished

theFile.close();
0
 
LVL 9

Expert Comment

by:bhagyesht
ID: 9640415
first tokenize using a tokenize function at vbcrlf
then check each token's 7 left characters if they match "ica-tcp" extract the username and run your if condition.

a tokenize function which returns an array is at
http://www.a1vbcode.com/coderedirect.asp?type=snippet&ID=2095
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:magsdtev
ID: 9651264
monkesdb
What language is your post in?  It looks like perl.  Do you have it in VBS?

bhagyesht
Do you have an example of this
0
 
LVL 9

Accepted Solution

by:
bhagyesht earned 250 total points
ID: 9655334
magsdtev: find example below
the code was written in vb so make any changes if required for vbs ie the variable declaration etc

Private Sub Command1_Click()
    Dim mytokens()
    Dim i
    Dim fileData
    fileData= ReadAllTextFile(<myfilename>)
    mytokens = tokenise(fileData, vbCrLf)
    For i = LBound(mytokens) To UBound(mytokens)
        If Len(mytokens(CInt(i))) > Len("ica-tcp#xx") Then
            If Mid(mytokens(CInt(i)), 3, Len("ica-tcp#xx") - 2) = "ica-tcp#" Then
                'your if condt
                MsgBox "true"
            Else
                ' your else condt
            End If
        End If
    Next i
End Sub


Public Function tokenise(strToTokenise As String, strUsingWhat As String) As String()
    Dim i
    Dim j
    Dim mystr()
    Dim strLen
    strLen = Len(strToTokenise)
    If strLen > 0 Then
        ReDim Preserve mystr(0)
    End If
    i = 1
    j = 0
    While i <> 0
        j = InStr(i, strToTokenise, strUsingWhat)
        If j <> 0 Then
            mystr(UBound(mystr)) = Mid(strToTokenise, i, j - i)
            i = j + 1
            ReDim Preserve mystr(UBound(mystr) + 1)
        Else
            mystr(UBound(mystr)) = Mid(strToTokenise, i)
            i = j
        End If
    Wend
    tokenise = mystr
End Function


Function ReadAllTextFile(strFilename)
   Const ForReading = 1
   Dim fso, f
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.OpenTextFile(strFilename, ForReading)
   ReadAllTextFile = f.ReadAll
   f.Close
   Set f = Nothing
   Set fso = Nothing
End Function
0
 
LVL 3

Expert Comment

by:monkesdb
ID: 9661461
hmm you could do that..

or you could be more sensible and use a function that does the same thing... Split.

myArray = Split(strToTokenise, strUsingWhat)

what could be more simpler.

and the language was C++, you know that obscure language that nobody uses.

doofus. chickenhead.

0
 
LVL 9

Expert Comment

by:bhagyesht
ID: 9668705
monkesdb : myArray = Split(strToTokenise, strUsingWhat)

isnt this quite similar to the tokenize function i wrote?

Public Function tokenise(strToTokenise As String, strUsingWhat As String) As String()

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
oracle query help 18 113
Java Loop 6 62
SCRIPT65535: Unexpected call to method or property access video html 5 explorer 3 64
Android development question 2 38
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
This is about my first experience with programming Arduino.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question