|
|
|||||||
Ok, I was assigned a long boring task, and thought "this looks like a job for KiXtart". However, I've only done logon scripting, registry editting, and file movement with it. Reading and manipulating text is not something I'm too familiar with. Ok, here is what I need to do, and I'll follow with what I want to do (I have to get the "need" done, since this project needs to be completed). Each user has a file in their home directory. So I need a script to go in their directory, open a file, search for a date, then copy from that location all the way to the end, and paste it (append) into a text file for me to look through. There are a few hundred users, so doing it by hand will take a loooong time. Now what I would 'like' to do is have kixtart build the user list itself, then search those drives, and grab all the info after a date specified via user input. Can anyone help me out here? |
||||||||
|
|
|||||||
Does the input file (the one you need to read from) have a structured layout? Assuming it does, then you could Code:
May not be perfect code, but should give you an idea |
||||||||
|
|
|||||||
Yes, the first entry of every line is the date (and I believe each entry is separated by a tab). The only thing I dislike about it is how it uses single digits (rather than 01/01/2006 it puts 1/1/2006, so sorting it in a spreadsheet app can get it mixed up). But anyway, I would just use a straight match, like "7/1/2006", and grab everything past that point. |
||||||||
|
|
|||||||
Would the script you wrote copy everything until the end of the file? |
||||||||
|
|
|||||||
Quote: Maybe this code is usefull and can be converted to KiX Look for "Enumerate all users in domain" CreateUserList2 |
||||||||
|
|
|||||||
without fully testing I will give you a conditional yes |
||||||||
|
|
|||||||
No, that won't help. There are several offices in the domain, and I only want to grab users who are here. Also, there is more than one server with user home directories. The best way I figured to do this is a batch file which will map a drive to one server, create a list of all the folders in the user directory, then do the same for the other servers. That's good enough, but the problem is having it take that list and turn it into something I can use. I can make the data array manually, but how would I create a dynamic one? Quote:Quote: |
||||||||
|
|
|||||||
these user drives, are they just folders in a share? if use, use something like dirplus to crawl all fo the files that you are looking for. Code: $files = dirplus("\\server\share",'/s1 /a-d /m datafile') that will return a file handle to each file 1 lvl deep, so the root of each users folder in the \\server\share. and only the files that have the name "datafile" in them. that should handle the file part... |
||||||||
|
|
|||||||
So I guess I should have clarified: I don't actually have trouble creating the user list (well, having KiXtart doing it rather than dos would be cleaner), my problem is having it dynamically create a data array to be used inside the script. |
||||||||
|
|
|||||||
If all of your directories are indeed under \users\ then you can use one of many different DIR UDF's found at http://www.kixtart.org/udf |
||||||||
|
|
|||||||
Well... kind of. The way the network security works, I can't use UNC paths, so I have to map network drives. But at that point, the folders would pretty much be X:\Office\Type\{username} Then all the users are inside that particular folder (so the only difference is the server and volume, which is irrelevant once the drive is mapped). |
||||||||
|
|
|||||||
Well I guess that's the problem, I need to know what different things I'm stringing together. I've never had KiXtart read files, so I'm out of my element. Also, I haven't used it in about four years, so my brain is all rusty overall Quote: |
||||||||
|
|
|||||||
As Bryce mentioned you can use DIRPlus() to create your array, it can be found at the link I provided. In your script you would then run the DIRPlus UDF to create your array of user folders, Then with that you can use the code that I provided and do a For Each $ in $Array to read the files |
||||||||
|
|
|||||||
Here is an overview of what I would like: 1. create list of folders in user directory 2. open user directory, and read "logfile.txt" 3. search logfile for a specific date, copy that point and everything to the end 4. paste that information into "userlogs.txt" 5. goto #2 until the end of the list. Then I will have a complete compilation of all the user's log files, starting at a certain date. |
||||||||
|
|
|||||||
Cool, I'm testing it out. I'm hoping to have this done by monday (boss is waiting for the info). |
||||||||
|
|
|||||||
my advice, dont beat your head in trying to reinvent the wheel... :P several UDF's out there to do the heavy lifting for you. Code:
|
||||||||
|
|
|||||||
BTW, thanks for all the help everyone! |
||||||||
|
|
|||||||
Ok, I've really been bummed out by this over the weekend. My skillz are gone, I can't seem to get anything working or even understand what I'm doing now. If someone can suggest to my burned-out brain how to string this together, I'll name my firstborn kid after you (pending spousal approval, so take it how you will). |
||||||||
|
|
|||||||
Can you please post an example of the LOG file so that we can see exactly what it is you're trying to copy, gather. Thanks. |
||||||||
|
|
|||||||
Sure. Actually, however, just to get this working I'm willing to be satisfied with taking the entire file, append them all into one file, and not worry about searching it. (quote marks added for clarity) "Day" "1/1/2006 5:55:55 PM" "username" "Server" "Computername" "IrrelevantData#1" "IrrelevantData#2" I don't know if the format comes through, but it's all separated by tabs. Here is what I would be happy with for right now, just so I can get this thing going: there are multiple shares to connect to \\Server1\share \\Server2\share \\Server3\share They have the same dir structure once a drive is mapped Location\data\{username} So I would like it to connect to the the first server, dir the data directory, then go inside each username directory. Open logfile.txt, and append it to one text file, then move on to the next folder until it runs out of user folders. At at that point, it will connect to the next server, and do the same thing. Then, finally, connect to the last server. Once that is done, I'll just work with the data in Excel and worry about sorting it for later. Sorry if I sound frantic, but I'm getting lots of pressure on this. I started just doing it by hand... but there are freaking hundreds of users, it's going to take half of forever! |
||||||||
|
|
|||||||
Ok this should give you a start... Code:
|
||||||||
|
|
|||||||
Tony the difficult part is we HAVE to know some EXACT marker to look for, otherwise very difficult to help you. In your example, will EVERY logfile have the exact same word Day followed by a TAB or will Day possibly be elsewhere or a different name ? I'm right in the middle of getting ready to rebuild my machine and I'm archiving off about 1/2TB so my system is a bit slow for doing much right now. Would love to help but we do need some EXACT details otherwise the text data part will be impossible to do. |
||||||||
|
|
|||||||
Well I see I'm a bit late and Garg has stepped up to the plate. Cool, was starting too feel a bit bad for you, but didn't really have the time to help all the way either right now. Thanks Gargoyle |
||||||||
|
|
|||||||
Well, as for that part, searching it is something I will worry about later. However... to answer your question: The "Day" field is a three letter abbreviation of the day posted in the following field, "Date". Truth be told, I can't see how it could be useful in any way, or why it would be there first. And, to specify, YES, it is ALWAYS three letters, and followed by a tab... which is good in this case: should be easier to skip programmatically. What I need to do is generate a monthly compilation of this list (it's a bit more involved, of course). So I would need to start at one date (7/1/2006) and grab everything after that. And of course it would be complicated by the fact that the user may not have anything in the file for that day, so you would have to also check for whatever days there ARE after that date (if they were on vacation, maternity leave, etc). However, this is intended to be run for the previous month, so it wouldn't get too far out of hand. Thanks for the code above, I'm going to go over it and try it out right now! |
||||||||
|
|
|||||||
Gargoyle: I tried your script out, but since it isn't mapping a drive it did not work (I can't use UNC paths in our environment). Now I'm assuming in $serveArray I enter "\\server\share"? Or just "server\share"? Also, one problem with the date: it doesn not use MM/DD/YYYY... it will use M/D/YYYY if the number is a single digit. |
||||||||
|
|
|||||||
You can easily enough change $Servarray to = your mapped drives EX: $Servarray = "q:", "x:", "y:" The Date portion you need to input, the MMDDYYYY was just a place holder As to your statement that you need that date or any date thereafter complicates things a bit as it will only check for the specific date that you specify |
||||||||
|
|
|||||||
Actually, how difficult would it be just to grab just a specific month/year (all 8/?/2006 and 8/??/2006)? Just for the moment, what can I chop out to get it to take all the users, find that file (if it exists), and dump all the contents into one file? |
||||||||
|
|
|||||||
For some reason I keep getting an "EndIf with no If" error on line 29. I can clearly see the If above it... wth? |
||||||||
|
|
|||||||
I customized some stuff, and it seemed to be running, but finally ended stating "invalid method/function call: missing comma!" on Line 22. Which... I think is If $3[0] = "MM/DD/YYYY So that doesn't make sense. I filled in the info with an actual date, but how does this handle not finding that date? Ugh. |
||||||||
|
|
|||||||
mismatched quote |
||||||||
|
|
|||||||
While does not have a next but a loop so this: Quote: Should be changed to: Quote: Look at the bold parts. |
||||||||
|
|
|||||||
I had a feeling this was going to happen. I've spent the last few hours trying to get this working, and it seems like all the trouble is caused by the problems with how the script searchs the text file. Can anyone just give me a quick hint to what to carve out to get it to just take the entire text file and append it to a combined log file? |
||||||||
|
|
|||||||
I specified having it write to "c:\temp\compile.txt", but the file is never there. A few times during testing it exited without error, but usually it keeps giving the "missing comma" error for the line with the date. Is there a way to have it write to the file each time it opens one of the user log files? Code: ;Script Options |
||||||||
|
|
|||||||
Well here is a condensed version (currently does not work properly but close). Perhaps Jooel or Mart or someone else has the time to help you complete it. The issue is in how the Open/Read/Write works - it finds the data, but then writes multiple times which it shouldn't do - just don't have time to further debug it. |
||||||||
|
|
|||||||
Ok, I removed the IF $3[0] = "8/1/2006" and the "EndIf". I'm crossing my fingers, hoping it will just make a dump of the whole file. |
||||||||
|
|
|||||||
Well you need to decide what you want. Do you want the entire file or just the line with the date you specified? |
||||||||
|
|
|||||||
My above comment was about Gargoyle's script. NTDOC, or someone else: is it easier if the script doesn't even care about the date, and just takes the all the log files and dumps their contents into one file? |
||||||||
|
|
|||||||
No, I never needed just one line: I was looking to start at the date and get that point and everything after it (or, specificly, to get an entire month- we would run it at the start of each month). I mentioned before, I would be more than happy just to have everything put together so I can sort it with Excel by hand. Since there are hundreds of users, it will be far easier to sort by hand and erase what I don't need. Other wise, I have to go to each folder, open the file, copy, paste, open the next user, etc. |
||||||||
|
|
|||||||
Damn, I was happy, it ran, but my elation was premature. It seemed to have written the info on the date specified about 20 times or whatever (I thought it completed the job, but when I went to sort the data I noticed). |
||||||||
|
|
|||||||
How can I make it start at line 1 and go to the end? For Next? |
||||||||
|
|
|||||||
Change this Code:
To this Code:
|
||||||||
|
|
|||||||
While - Loop, not Next |
||||||||
|
|
|||||||
Code:
|
||||||||
|
|
|||||||
Cut and paste - My bad |
||||||||
|
|
|||||||
Gargoyle: I've never gotten your script to run. It sits there for about 15 minutes, then usually errors out, and never even creates an output text file (this last time I got a "undefined variable [Nul]!" error. I'm assuming it ran out of log files... but it has never generated any output text file. Does it have to finish running before it will write an output file? |
||||||||
|
|
|||||||
It should create the file right off. You may want to run it in debug mode so that you can see exactly where it is having an issue. As for the $Nul, that is because it was added after the fact, and it is not Dimmed, and the explicit option is turned on. |
||||||||
|
|
|||||||
Actually, the one NTDoc has above I managed to get working after inserting a few pieces of site-specific info: it goes into each user's directory and the text file gets written. Could someone just recommend what to change in that one so it will either take all the entries for a specified month, or else just grab everything? Which ever is fastest and easiest at this point: the people waiting on this are getting very impatient that it's not done. My problem, I know, but aaaaaaaaaargh. It sucks knowing I once knew how to do this, and can't remember at all. I must have lost several points of int somewhere... and didn't have any to spare in the first place. |
||||||||
|
|
|||||||
You can alway's just take the output from DirPlus and concanate the files into one. Copy $File1+$File2+$File3 OutputFile.txt |
||||||||
|
|
|||||||
Is there any way to handle it like a DOS Code:
For some reason I remember the DOS stuff, but KiXtart has faded away |
||||||||
|
|
|||||||
Wow... did I just answer my own question? I'll test it out... I might be able to do a Code: SHELL "CMD.EXE type logfile.txt>>C:\temp\compile.txt" Wish me luck. |
||||||||
|
|
|||||||
Damn, it isnt working. For some reason, it will type the log file, but it isnt piping it into compile.txt |
||||||||
|
|
|||||||
Code:
This is untested, but may do the job of concatanting all the files together. |
||||||||
|
|
|||||||
Is this for your script or NTDOC's? Where would I insert this (and what would I replace)? |
||||||||
|
|
|||||||
Tony, Okay, so lets copy all the files into a single file. Are you sure that's what you want? I don't see how you're going to know who's data is whos that way. I'll make a code change that will work just fine and post it in a minute, but really think that is not going to work for you. What version of KiXtart did you say you're using? |
||||||||
|
|
|||||||
SHELL "%comspec% /c type logfile.txt >>C:\temp\compile.txt" |
||||||||
|
|
|||||||
Okay here you go. This will copy all the logfile.txt files into a single file (you need to modify your locations, etc..) |
||||||||
|
|
|||||||
Hmmm just thinking of this method though. If you had hundreds of files it would not work as the command line would be too long. Though slow I think you may have to do the redirect of each file into a single file. |
||||||||
|
|
|||||||
I'm using the 2010.452. Having it all in one file is fine: I'll just sort it with Excel. If I sort everything by the date column, I can remove everything not in the month I want. Then I remove certain other details, and I'm done. |
||||||||
|
|
|||||||
Okay, this method should work regardless of the amount of files you need to process. |
||||||||
|
|
|||||||
Is there any way to have it do my suggestion from before, just have it use DOS and do a "type logfile.txt>>compile.txt"? I tried it myself, but I wasn't sure if I was screwing something up. |
||||||||
|
|
|||||||
You missed the /c |
||||||||
|
|
|||||||
ah ok, cool. I'll try it out right now! Thanks again to everyone! |
||||||||
|
|
|||||||
The above code I just posted does that. |
||||||||
|
|
|||||||
Ah I see. |
||||||||
|
|
|||||||
w00t!!! It worked!! Thanks a ton. I'll probably revisit this some time to figure out a way to have it sort the file, but for now this is perfect!! My firstborn will be named NTDoc. Hope he doesn't get picked on in school =) |
||||||||
|
|
|||||||
You're welcome. Like said. You can get just the specific data you want, but you have to ver VERY specific on the format and details. Otherwise one wastes time trying to accomodate unknown data. |
||||||||
|
|
|||||||
Yeah, I have a few ideas about getting it, but I'll wait til later (since I'm looking for just the month, it only needs to look at the first two characters in the date, and get rid of the "\" if it uses a single digit. The file always has a three letter day, followed by a tab, followed by the date). I just finished removing all the stuff I didn't need by sorting with Excel. It needs to have more stuff taken out (we are looking for a specific pattern), but this is the big piece everyone was waiting on. Woohoo!! |