Page 1 of 2 12>
Topic Options
#100771 - 2003-05-07 06:47 PM How do I check a CSV for a string?
MaestroG Offline
Fresh Scripter

Registered: 2002-12-30
Posts: 28
Loc: Tulsa, OK
I read the comments on the latest KixGolf tourney thread, but it's all way over my head.

My KiXtart logon script creates a CSV to record PC information (like OS and computer name) when a user logs on. I only want one entry per computer so after that section of code runs I create a file on the C:\ drive of the PC. I also put an "If Exist" statement before that section of code and if all goes well, I only get one entry per PC in the CSV.

This seems hokie. Couldn't I do something similar like an If Instr() to look inside the CSV for that computer name if not found, run the code? I know If Instr() won't work, but is there something that does or some way to accomplish this?

I appreciate this forum. [Smile]
Thanks,
G

Top
#100772 - 2003-05-07 06:57 PM Re: How do I check a CSV for a string?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
you have 2 pretty simple ways...

1) instead of csv use ini-file with which you can easily check if it's there.
and you can even write it again and again and still there will be only one entry, the newist.
2) you can shell to command-prompt and with find and @error you can check if there is already data for that wksta on the file.
this is not recommended way as you have no easy way of knowing how old the data in the file is etc...
_________________________
!

download KiXnet

Top
#100773 - 2003-05-07 07:08 PM Re: How do I check a CSV for a string?
MaestroG Offline
Fresh Scripter

Registered: 2002-12-30
Posts: 28
Loc: Tulsa, OK
Cool! [Eek!] I like the ini file idea. Do you know if there is documentation out here somewhere about the procedures and the gotchas for this new way?
Top
#100774 - 2003-05-07 07:12 PM Re: How do I check a CSV for a string?
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Nothing hard here. Check out ReadProfileString and WriteProfileString.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#100775 - 2003-05-07 07:15 PM Re: How do I check a CSV for a string?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
sure there is but dunno where [Wink]

it's all about using writeprofilestring() in your script...

writeprofilestring("Path\file","Key","value","data")

so it could be:
$return=writeprofilestring("\\server\share\file.ini","@wksta","checkdate",@date)
$return=writeprofilestring("\\server\share\file.ini","@wksta","system",@producttype)

as example [Wink]
and so on
_________________________
!

download KiXnet

Top
#100776 - 2003-05-07 08:36 PM Re: How do I check a CSV for a string?
MaestroG Offline
Fresh Scripter

Registered: 2002-12-30
Posts: 28
Loc: Tulsa, OK
Thanks guys! [Smile]

It does look pretty straight forward and painless.

Cudos! [Cool]

Top
#100777 - 2003-05-07 10:26 PM Re: How do I check a CSV for a string?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
If you want an example of manipulating a .ini file you can also take a look at this post.

Replace a value in an INI file
http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=1;t=007101

Top
#100778 - 2003-05-08 01:37 AM Re: How do I check a CSV for a string?
BoxKite Offline
Da Box
*****

Registered: 2000-05-17
Posts: 282
Loc: Vacaville,CA,USA
Hmmmm....
Hmmmm....

MaestroG, if two users logon at the same time, are they both trying to write to the same file? I ask because one of the users will not have access to the file because the 1st person to gain access will put an exclusive lock on the file until the script completes the process. This means one person will drop through the script.

If you want to get a fresh file at each logon, and use the information in Excel, see my reply to the following:

Fresh tex

By the by, are you into rap music? [Big Grin] [Big Grin] [Big Grin]

[ 08. May 2003, 01:40: Message edited by: BoxKite ]
_________________________
Box
FACTA NON VERBA

Top
#100779 - 2003-05-08 01:43 AM Re: How do I check a CSV for a string?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well, G says "I create a file on the C:\ drive" so there should not be any contention issues there.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#100780 - 2003-05-08 01:51 AM Re: How do I check a CSV for a string?
BoxKite Offline
Da Box
*****

Registered: 2000-05-17
Posts: 282
Loc: Vacaville,CA,USA
I think he is saying the file is created on the same C drive. If not, you are right. [Confused]

Maybe G will clarify that for us.
_________________________
Box
FACTA NON VERBA

Top
#100781 - 2003-05-08 05:43 PM Re: How do I check a CSV for a string?
MaestroG Offline
Fresh Scripter

Registered: 2002-12-30
Posts: 28
Loc: Tulsa, OK
That's a good point. I am writing the current CSV as one file in a central location that all open and write to. I don't know if there are lock issues going on or not. Like I said...the whole thing is hokie. I'm a novice KiXtart'er so my stuff is rudimentary at best because I patch borrowed code together until it does what I want! [Embarrassed]

Anyway...at present, the script gets PC Info and writes it to a CSV on my server and then copies a file from my server to the C:\ drive of the user's PC. Next time they logon, it checks for that copied file on local C:\ and if there, skips the code that gets info and writes to the CSV.

I am all about leaving the end-user PC out of the mix. I'd rather have the Kix logon script write the PC Info to a file of some kind and then next time around do it again and overwrite the previous data for that particular PC...its own entry (I thought of CSV only because was easy to make into a nice spreadsheet). That way, every logon gathers PC data and if something has changed, it is updated.

It seems INI file idea may help me accomplish this, but there still is the file lock question. What happens when 250 people logon at the same time?

BTW - here's my current code...

code:
 
If Exist($systemdrive+'\pcdata.ok')
Gosub "End"
Else Gosub "WriteInfo"
EndIf

:WriteInfo
$s = OpenFile("\\server\share\file.csv", "W", 1, 0)
If @error = 0
WriteLine($s, "@DATE, @TIME, @WKSTA, @USERID, @FULLNAME" + @CRLF)
Close($s)
EndIf
Copy $Netlogon+'\tempfile.tmp' $systemdrive+'\pcdata.ok'


Anyone have any good ideas? [Smile]

Top
#100782 - 2003-05-08 05:46 PM Re: How do I check a CSV for a string?
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Use an Microsoft Access database instead on the shared drive and write to it via the DBCommand() UDF. Access can comfortably handle multiple concurrent read/write accesses. Files will get locked when writing to them.
_________________________
There are two types of vessels, submarines and targets.

Top
#100783 - 2003-05-08 05:50 PM Re: How do I check a CSV for a string?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
doh, if db during logon is not overkill, I must wonder what is.

don't spook the man [Big Grin]
_________________________
!

download KiXnet

Top
#100784 - 2003-05-09 03:00 AM Re: How do I check a CSV for a string?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
Maestro,

Here is another example of what you appear to want to do.

Writing to a CSV file
http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=1;t=007117

This is about the EASIEST (not the only way) for someone that is new to KiXtart.

Jens has a lot of good ideas and code, but updating a databse during logon is not a beginner task.

Please read the full posting on the above topic.

Top
#100785 - 2003-05-10 12:11 AM Re: How do I check a CSV for a string?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
eh?
isn't that again too hard...
lets see...

could someone come up with sample that their .ini files hasn't been updating?

has someone even tried to code around that?
_________________________
!

download KiXnet

Top
#100786 - 2003-05-09 08:40 PM Re: How do I check a CSV for a string?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
Well I have not tried, but I would assume that a single .ini file being updated by 1,000+ users at the same time might be an issue for file lock.

Another reason I personally don't use the .ini method is that I want a single line of data for import to Excel, however, I guess one might be able to duplicate that in an .ini file, but then the import to Excel would not work easily, you would have to code an extraction of data to Excel. I'm sure it could also be done, but then we have strayed from the SIMPLE again.

That is how I see it, perhaps though you or someone else could shed light for another method that is as simple or more simple. Keeping in mind that MS Excel is the final tool used for printing the report as preferred by my Management.

Not easy, but I like the idea of doing a live database update that Jens has, I'm just afraid of errors connecting, corruption not caught in time, etc... I might have to try it out some time though on a limited basis in the future.

Top
#100787 - 2003-05-09 08:55 PM Re: How do I check a CSV for a string?
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Remember: http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=1;t=006118#000009

INI file can cause excessive network traffic in larger, busy environments.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#100788 - 2003-05-09 10:27 PM Re: How do I check a CSV for a string?
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
And you'll have file-lock issues when multiple users try to write to it. I normally only use it to read configurations from it. However, one can alwasy write to dedicated @WKSTA.INI files and have a second script merge them into Excel. But at that time, one could write to Excel directly via ODBC driver or the Excel UDFs.
_________________________
There are two types of vessels, submarines and targets.

Top
#100789 - 2003-05-10 02:39 AM Re: How do I check a CSV for a string?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
heh...
sounds like jens is starting to repeat himself [Wink]

quess the ini-file crap is the reason why I use registry [Wink]
have a dedicated machine for info-collection makes everyones life easier.

and what comes to that excel stuff...
sure, ini2excel is about 5 lines of code and if done in excel macro... 10 lines.

anyway, one should never see excel-files as the information store-format.
never ever as that is incompatible with most of the other programs.
thus the CSV would anyway be the best resulting way of making the ending file.
and with about 5 lines of html-code you make it look just as fancy in IE than in excel... just as long as you remember not to make it excel-file.
_________________________
!

download KiXnet

Top
#100790 - 2003-05-10 05:24 AM Re: How do I check a CSV for a string?
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
Let see you sort that IE page anyway you feel like sorting, without coding. That is why Excel is the reporting tool of choice. Not saving the file, that is still CSV.
Top
Page 1 of 2 12>


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 611 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.075 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org