Page 1 of 1 1
Topic Options
#210033 - 2015-03-05 02:00 PM comparing txt-file (with multiple lines) with information from AD
Curious Offline
Getting the hang of it

Registered: 2004-02-16
Posts: 61
Hello.

I've made a script that compares information from AD with information from a txt-file (that has collected info from AD in previos steps).

I want the script to detect whether info has changed, and then run commands if change has been detected.

The txt-file collects various information, totally consisting of 6 lines (each line finished with CR), allthough the file has even more lines after what needs to be checked. That's why I've used the counter.

Reading this info with readline is ok, but what I can't accomplish is to detect if one of the lines is empty, and then compare with that field in AD (which has got new information), and when f.ex a field has got info, stuff needs to be done.

I could have written a bunch of if/endif's, but there's gotta be easier ways.. Maybe one solution is to use an ini-file?

As you can see, what I have right now, is only a check that detects changes - with a bunch of or-syntaxes. This method leads to empty lines to fall through.

 Code:
if open (8, $Log + "\user\" + @userid + ".txt") = 0
while @ERROR = 0 and $Counter < 7
	$Counter = $Counter + 1 ; Use $counter in addition to while because of the possibility to limit the count of lines to be checked
	$x = ReadLine(8)
	? "Line read: [" + $x + "]"
	 if $x = $strName or $x = $strTitle or $x = $strMail or $x = $strDepartment or $x = $strPhone or $x = $strMobile
	 $Change = "no"
   else
	 $Change = "yes"
	 $DoStuff = "yes"
	 $Tekst2 = $Tekst2 + $x + ", "
   Endif
Loop
	
EndIf
Close (8)


So.. it's better to ask you guys if you've got any directions.

Regards


Edited by Curious (2015-03-05 02:34 PM)
_________________________
I was placed on earth to do a job. Right now I have so much to do, I will never die..

Top
#210034 - 2015-03-05 02:40 PM Re: comparing txt-file (with multiple lines) with information from AD [Re: Curious]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
It might be better to explain your project more, and we might suggest an alternate method to achieve your goal.

The fnLDAPQuery() UDF is great at gathering data from AD. I've used this to gather and manipulate data for large (40,000+ user object) AD migrations. In some cases, it was faster/easier to collect the data with Kix and save it as .CSV, then use Excel to filter the data into a format that Kix could then use for the actual manipulation. Yes - it could have been done all with Kix, but the user data was inconsistently formatted and it was faster to do a visual check than write code for all the possible exceptions.

As for your script, don't use "yes/no" for flags - use 0 or 1, then you can simplify the tests:
 Code:
$Change = 0
If A <> B
  $Change = 1
EndIf
; more stuff...
If $Change
  ; do other stuff for changes..
EndIf
Look at my Bool() UDF, which converts values like "True/False", "Yes/No", and "On/Off" to Boolean values if you need to translate human-readable values into simpler versions for fast comparisons.

Be sure you init your counter to 0 where needed, or it will only work for the first iteration.

Consider a Select/Case/EndSelect for individual comparisons, since only one match is possible, it's easier than multiple IFs and less confusing than many AND/OR comparisons.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#210036 - 2015-03-05 02:58 PM Re: comparing txt-file (with multiple lines) with information from AD [Re: Curious]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
without actually bothering to read Glenn's insightful message right now, I suspect your text file is just a bunch of data with no ties to anything.
aka,
 Quote:

sam jacks

sam.jacks@mailer.ding


555-5255
lisa hicks

lisa.hicks@mailer.8ding

555-55552
555-52525


now, since all users most likely have at least one field empty, you will never see if something has changed, since that empty value will always satisfy the empty lines.

again, I might be incorrect since you did not provide enough info but guess on it.
if this is the case, switch to ini's will indeed be helpful or change your txt syntax to something more like:
 Quote:

name:sam jacks
title:
mail:sam.jacks@mailer.ding
dept:
phone:
cell:555-5255


that way you will actually be tracking the empty fields as well.
_________________________
!

download KiXnet

Top
#210037 - 2015-03-05 03:28 PM Re: comparing txt-file (with multiple lines) with information from AD [Re: Lonkero]
Curious Offline
Getting the hang of it

Registered: 2004-02-16
Posts: 61
Thanks for the response guys...

While I was waiting for you clever guys to respond, I dived into the use of ini-files instead. Quick and dirty it might seem like I've solved the "mystery", so hold on your horses, I will post more if further assistance is needed.

Thanks \:\)
_________________________
I was placed on earth to do a job. Right now I have so much to do, I will never die..

Top
Page 1 of 1 1


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

Who's Online
0 registered and 1045 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

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

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