#210033 - 2015-03-05 02:00 PM
comparing txt-file (with multiple lines) with information from AD
|
Curious
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.
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
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:$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!
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1045 anonymous users online.
|
|
|