Page 1 of 2 12>
Topic Options
#43379 - 2003-07-26 06:22 AM writing to log file on remote server
JohnQ Offline
Starting to like KiXtart

Registered: 2003-03-04
Posts: 171
I'm sure this question has probably been asked before, but here it is again. When using a script that is going to write info to a file on a remote server, what is the best method to use? The amount of data written is fairly small - approx 100 characters, but there is the potential for many workstations to be writing to the file at the same time.

I have used RedirectOutput and WriteLine . Both seem to work fine, but I'm curious if one is better than the other or if it's just a matter of personal preference.

How big of an issue is contention? I want to make sure that any workstation that needs to write to the file will be able to do so.

Thanks in advance for any insight.

Top
#43380 - 2003-07-26 01:08 PM Re: writing to log file on remote server
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
The solution I use which avoids any contention at all is to use WriteLog2() ,in the UDF library, and write to a file name based on the computername. Then use another process to collect and consolidate the information.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#43381 - 2003-07-26 01:52 PM Re: writing to log file on remote server
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
For workstation logging (initial inventory purposes) I just left it alone with possible contentions but after a few days, all the workstation data gets in, as even on a perfect day, very few people log in at the same time consistently.

However subsequently, I have implemented an Access MDB for inventory, will allows multiple concurrent connections...

NTDOC's preferred method is to create the log files on the client machine (@wksta.log) and then copy to the server. no contentions, old data is overwritten by new, and an admin script he uses appends all their data into a single sheet
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#43382 - 2003-07-26 02:22 PM Re: writing to log file on remote server
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
One other way would be an ini file which also is accessible simultaneously...

For an example with creating an excel sheet of that log from an admin workstation see the last replies in
this topic
_________________________



Top
#43383 - 2003-07-26 03:06 PM Re: writing to log file on remote server
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Caution should be exercised when having multiple accesses to an INI file.

See: WriteProfileString() Internals?
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#43384 - 2003-07-26 03:12 PM Re: writing to log file on remote server
JohnQ Offline
Starting to like KiXtart

Registered: 2003-03-04
Posts: 171
We're talking several thousand users here. They won't all be writing to the file, but based on certain conditions some will and I would think with that many users there is a possibility that more than one user could be trying to access the file at the same time.

When using RedirectOutput or WriteLine, if user A has the file open for write purposes and user B needs to write at the same time, does user B skip it because it's already open or does he wait?

Why or how can multiple people write to an ini file at the same time but not to a regular file? Does it have to be in any special format?

Top
#43385 - 2003-07-26 03:16 PM Re: writing to log file on remote server
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
A locked file is a locked file. Only one person, the one that has the lock can write to it.

Using unique files names like those based on @wksta will eliminate this issue. Please review the link I posted above about WriteProfileString.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#43386 - 2003-07-26 03:42 PM Re: writing to log file on remote server
JohnQ Offline
Starting to like KiXtart

Registered: 2003-03-04
Posts: 171
Howard, I think your idea of creating a seperate file on each workstation and then copying the files to a central location would be the easiest.

The only problem is, I will need to combine the contents of each of those into one file. Each file shouldn't have more than one or two lines to copy.

I've been searching for some examples, but haven't found anything yet. Maybe I'm making this harder than it should be.

Top
#43387 - 2003-07-26 03:49 PM Re: writing to log file on remote server
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Actually, someone else write locally and copies. I would just write to "\\server\share\" + @wksta + ".log"

Depending how you format the file would determine what needs to be done to consolidate the data.

You could enumerate the file names, open each one, read the data, parse if necessary, and write a new file.

Or I think you could do something as simple as:

copy *.log newfile.txt

[ 26. July 2003, 15:50: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#43388 - 2003-07-26 04:01 PM Re: writing to log file on remote server
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Another problem is that even if you only write a couple of bytes, the whole logfile must be read to memory (implies transmission over the network).

Especially with thouands of clients, it might be advisable to switch to a database approach, e.g. an MS Access/SQL Server/MySQL database. This will allow multiple users to log information at the same time and the file needs not be transferred across a network.

The second solution would be to create a new log file on a per-computer and -per-day or per-week basis supplemented by an administartive script that concacenates these logfiles for later analysis.

The third solution would be to create the log files on the local computer and copy them over to a central location via client or central admin script.

However, based on the number fo cleint I wuld implement the database and nothing else, as SQL queries will enable you to automatically generate various reports on the logs.

Appropriate database DB...() UDFs are located in the UDF Forum.
_________________________
There are two types of vessels, submarines and targets.

Top
#43389 - 2003-07-26 04:01 PM Re: writing to log file on remote server
JohnQ Offline
Starting to like KiXtart

Registered: 2003-03-04
Posts: 171
I tried copy *.log newfile.txt but it overwrites the newfile.txt with the contents of the last file in the group.

The individual files are just simple csv files. I guess I just need to figure out an easy way to open each one, read the lines and write them to another file.

Top
#43390 - 2003-07-26 04:04 PM Re: writing to log file on remote server
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
The COPY shows the expected behavior. The SHELL COPY command can concacenate multiple files
code:
shell '%comspec% /c copy file1.txt+file2.txt file3.txt'

However, as your file are already in CSV-format I'ds really highly recoomed the database approach, it'll make analysis easy.
_________________________
There are two types of vessels, submarines and targets.

Top
#43391 - 2003-07-26 04:06 PM Re: writing to log file on remote server
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Sorry about the copy thing.

Try this:

type *.log >> completelog.txt
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#43392 - 2003-07-26 04:08 PM Re: writing to log file on remote server
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
TYPE is a console command, FYI, not a KiXtart command. [Wink]
_________________________
There are two types of vessels, submarines and targets.

Top
#43393 - 2003-07-26 04:30 PM Re: writing to log file on remote server
JohnQ Offline
Starting to like KiXtart

Registered: 2003-03-04
Posts: 171
Using Shell '%comspec% /c type *.log >> newlog.txt' works fine. I assume that's probably the easiest and fastest approach.

Jens, I already have a stored procedure written in TSQL that a buddy of mine created for me. It pumps everything in the log file into the SQL DB and updates any dupes with the most current date/time stamp. My problem was, after the contention issue surfaced, I just needed to figure out a easy way to recreate just the one large log file. Thanks for all of your input!

Top
#43394 - 2003-07-26 04:35 PM Re: writing to log file on remote server
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
If you already have SQL stuff in place, then you should write the logs directly into the database. This will eliminate pretty much all the shortcomings of the text file approaches, especially considering the userbase, and it will also decrease network traffic due to the logging.

Take a look at for example the DBCommand() UDF in the UDF Forum.

[ 26. July 2003, 17:27: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#43395 - 2003-07-26 05:24 PM Re: writing to log file on remote server
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
or go to my site and see the example inventory script for Access there.
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#43396 - 2003-07-26 06:06 PM Re: writing to log file on remote server
JohnQ Offline
Starting to like KiXtart

Registered: 2003-03-04
Posts: 171
Jens, I took a look at your UDFs for databases. I am not very familiar with ADO and honestly, can't even figure out how to retrieve a simple recordset using your UDFs. Maybe I'm confused because there are so many functions involved. There's one to open, one to retrieve a recordset, one to exectue, one to close...

If you have time, could you provide a short sample using a SQL server connection? Something very basic like just returning a simple recordset. Something simple like:

select * from tbl_blah

If you don't have time or don't want to, I understand. Anyway, thanks for all of your help and insight.

Top
#43397 - 2003-07-26 06:15 PM Re: writing to log file on remote server
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
That's why there is DBCommand() - Executes a SQL statement and returns a recordset if applicable , it's a superset of the other database UDFs. Example code, see also the UDF headers
code:
$dsn='DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=\\server\writableshare\database.mdb'
$sql="INSERT INTO Table1 VALUES('eee','fff')"
$recordset = DBCommand($dsn,$sql)
? 'Error = '+@ERROR+' - '+@SERROR
$sql="SELECT Field1, Field2 FROM Table1"
$recordset = DBCommand($dsn,$sql)
? 'Error = '+@ERROR+' - '+@SERROR
for $row=0 to ubound($recordset,1)
for $column=0 to ubound($recordset,2)
? 'Field(row='+$row+', column='+$column+') ='+$recordset[$row,$column]
next
next



[ 26. July 2003, 18:15: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#43398 - 2003-07-26 09:46 PM Re: writing to log file on remote server
ChristopheM Offline
Hey THIS is FUN
*****

Registered: 2002-05-13
Posts: 311
Loc: STRASBOURG, France
hello JohnQ,

what is the problem with combining all log files ?
if you use kix script for login script or other, it wouldn't be a problem to concatenate
I have been using this method with more than 2800 workstation for four years and it's very efficient.

Now, i also use this for "heavy" distribution.
for current software installation, I use SMS but for service pack installation and other big updates, i have kix script that write log file named @wksta.log on a shared directory. I can see workstation that are installing, installation OK and KO, installation that will come because the start of installation is based on a host file with hostname and date for installation.

I don't know what is important for you :
having information immediately online
or
not having problem of lock file

in my case, i have choiced : no lock problem.
I prefer to wait one or two minutes to concatenate 2800 files and load the result in an excel sheet.

[ 26. July 2003, 21:48: Message edited by: Christophe Melin ]
_________________________
Christophe

Top
Page 1 of 2 12>


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

Who's Online
0 registered and 874 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.077 seconds in which 0.03 seconds were spent on a total of 14 queries. Zlib compression enabled.

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