#39767 - 2003-05-02 12:47 AM
Writing to a CSV file
|
Grasshopper75
Getting the hang of it
Registered: 2002-01-15
Posts: 99
Loc: Melbourne, Australia
|
Hi All,
I've just stumbled back into Kix after a 6 month leave of absence. I am currently writing a script to roll-out Windows NT SP6a and have written a file to audit a users' PC.
code:
$AuditFile=("s:\Logs\audit.csv") $IEVersion = ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer","Version") $Freespace=GetDiskSpace (C:) If Open( 3 , $AuditFile , 5 ) = 0 WriteLine( 3 , "@DATE,@TIME,@WKSTA,@USERID,@FULLNAME,$FREESPACE Kb,@PRODUCTTYPE @CSD,Internet Explorer $IEVERSION @CRLF") Else Beep ? "failed to open file, error code : [" + @ERROR + "]" EndIf
Now to avoid the issue of a PC not running the audit if the file is being written to by another user I want to include a WHILE-LOOP but don't know where to put it. Can anyone help ?
Cheers, Grasshopper75
|
|
Top
|
|
|
|
#39768 - 2003-05-02 12:52 AM
Re: Writing to a CSV file
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Two suggestions: 1) Look into WriteLog2() 2) Use the computer name (@wksta) as the audit file name.
This will avoid any chance of a write conflict problem. You then can use another program to consolidate the the data.
|
|
Top
|
|
|
|
#39772 - 2003-05-01 04:20 PM
Re: Writing to a CSV file
|
Rocco Capra
Hey THIS is FUN
   
Registered: 2002-04-01
Posts: 380
Loc: Mansfield Ohio
|
|
|
Top
|
|
|
|
#39773 - 2003-05-01 05:34 PM
Re: Writing to a CSV file
|
Grasshopper75
Getting the hang of it
Registered: 2002-01-15
Posts: 99
Loc: Melbourne, Australia
|
Each user will execute the code wen they log on so there is a possibility that more than one user is attempting to write to the file at the same time. I am happy to implement Howard's suggestion of giving the log file the workstation name and creating a log for each workstation though does anyone know of any easy way to consolidate this information ? Failing that yes I would like a WHILE loop with a timeout but again where do I put that code ?? I'm a bit confused on where to put it based on the error code for the file being open.
|
|
Top
|
|
|
|
#39782 - 2003-05-01 06:38 PM
Re: Writing to a CSV file
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
The easiest way to consolidate the workstation name based files would be to use WSHPIPE, one of the DIR type udfs, or the KiXtart DIR command to gather a list of files in the directory. Then open and read the files using WriteLog2 to write the consolidate data file.
|
|
Top
|
|
|
|
#39785 - 2003-05-01 11:33 PM
Re: Writing to a CSV file
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11628
Loc: CA
|
Boy, I'm glad I don't work where you guys are. Way too many LOOPS/WAITS/SLEEPS/etc...
Do your people ever get to logon?
Howard already told you how to do it, and you guys seemed to have ignored his suggestion.
Basically you write a log file for each computer, then you copy that data into a single file and import with Excel.
Here is a basic idea (code has not been tested)
$AuditFile=("s:\Logs\"+@WKSTA+".LOG") IF EXIST ($AuditFile) DEL ($AuditFile) ENDIF $IEVersion = ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer","Version") $Freespace = GetDiskSpace("C:\") /1024 IF OPEN(1,$AuditFile, 5)= 0 $out = WriteLine(1, "@DATE+"*"+@TIME+"*"+@WKSTA+"*"+@USERID+"*"+@FULLNAME+"*"+$FREESPACE+"*"+@PRODUCTTYPE+"*"+@CSD+"*"+$IEVERSION+"*"+@CRLF") $x = CLOSE(1) ENDIF
Then from your workstation in a batch file you run
@ECHO OFF COPY s:\Logs\*.LOG C:\REPORTS\INVENTORY.TXT
Then you run Excel and you open C:\REPORTS\INVENTORY.TXT and you remove all delimiters and add the * as the delimiter I don't use the , as I find that too often it is used in names or other areas that will screw up your import to Excel. Have not found very many applications or names that use the * so that is why I use it. Now you should have a very nice list of Systems and their data.
And no file locking/waiting to deal with.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 837 anonymous users online.
|
|
|