Page 1 of 4 1234>
Topic Options
#167767 - 2006-09-15 10:01 PM Need some help
Tony72 Offline
Getting the hang of it

Registered: 2002-06-18
Posts: 53
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?
_________________________
Be kind; each person is fighting his own private war.

Top
#167768 - 2006-09-15 10:19 PM Re: Need some help
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Does the input file (the one you need to read from) have a structured layout?

Assuming it does, then you could
Code:

Open(1,"YourFileHere.TXT",2"

Do $ = Split(Readline(1)," ") Until $[0] = "InsertDateHere"
Open (2,"YourOtherFile.TXT",5)
While @Error = 0
Writeline (2,$R+@crlf)
$R = Readline(1)
Next
Close(1)
Close(2)



May not be perfect code, but should give you an idea

Top
#167769 - 2006-09-15 11:15 PM Re: Need some help
Tony72 Offline
Getting the hang of it

Registered: 2002-06-18
Posts: 53
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.
_________________________
Be kind; each person is fighting his own private war.

Top
#167770 - 2006-09-15 11:19 PM Re: Need some help
Tony72 Offline
Getting the hang of it

Registered: 2002-06-18
Posts: 53
Would the script you wrote copy everything until the end of the file?
Top
#167771 - 2006-09-15 11:50 PM Re: Need some help
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Quote:


kixtart build the user list itself




Maybe this code is usefull and can be converted to KiX
Look for "Enumerate all users in domain"
CreateUserList2

Top
#167772 - 2006-09-16 12:06 AM Re: Need some help
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
without fully testing I will give you a conditional yes
Top
#167773 - 2006-09-16 12:21 AM Re: Need some help
Tony72 Offline
Getting the hang of it

Registered: 2002-06-18
Posts: 53
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:


kixtart build the user list itself




Maybe this code is usefull and can be converted to KiX
Look for "Enumerate all users in domain"
CreateUserList2


_________________________
Be kind; each person is fighting his own private war.

Top
#167774 - 2006-09-16 12:25 AM Re: Need some help
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
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...

Top
#167775 - 2006-09-16 12:25 AM Re: Need some help
Tony72 Offline
Getting the hang of it

Registered: 2002-06-18
Posts: 53
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.
Top
#167776 - 2006-09-16 12:27 AM Re: Need some help
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
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
Top
#167777 - 2006-09-16 12:30 AM Re: Need some help
Tony72 Offline
Getting the hang of it

Registered: 2002-06-18
Posts: 53
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).

Top
#167778 - 2006-09-16 12:32 AM Re: Need some help
Tony72 Offline
Getting the hang of it

Registered: 2002-06-18
Posts: 53
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:

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


_________________________
Be kind; each person is fighting his own private war.

Top
#167779 - 2006-09-16 12:36 AM Re: Need some help
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
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

Top
#167780 - 2006-09-16 12:37 AM Re: Need some help
Tony72 Offline
Getting the hang of it

Registered: 2002-06-18
Posts: 53
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.


Edited by Tony72 (2006-09-16 12:39 AM)

Top
#167781 - 2006-09-16 12:47 AM Re: Need some help
Tony72 Offline
Getting the hang of it

Registered: 2002-06-18
Posts: 53
Cool, I'm testing it out. I'm hoping to have this done by monday (boss is waiting for the info).
Top
#167782 - 2006-09-16 12:47 AM Re: Need some help
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
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:

for each $file in dirplus('X:\Office\Type','/s1 /a-d /m logfile.txt')
? $file.path + $file.name

$filedata = loadfile($file.path+$file.name)

/* at this point, i dont knwo wht your data looks like,
but the variable $filedata should be the entire contents of logfile.txt
that was found in one of the users folders.

This code uses 2 UDF's Dirplus() and Loadfile() */


next


Top
#167783 - 2006-09-16 12:47 AM Re: Need some help
Tony72 Offline
Getting the hang of it

Registered: 2002-06-18
Posts: 53
BTW, thanks for all the help everyone!
Top
#167784 - 2006-09-19 01:03 AM Re: Need some help
Tony72 Offline
Getting the hang of it

Registered: 2002-06-18
Posts: 53
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).

Top
#167785 - 2006-09-19 02:02 AM Re: Need some help
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
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.

Top
#167786 - 2006-09-19 04:08 AM Re: Need some help
Tony72 Offline
Getting the hang of it

Registered: 2002-06-18
Posts: 53
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!

Top
Page 1 of 4 1234>


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

Who's Online
1 registered (Allen) and 382 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.072 seconds in which 0.026 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