Jump to content

batch files and writing to csv file


Recommended Posts

Posted

Hello,

 

I have logon and logoff batch files that I wrote and applied to a group

policy to find out when people are logging on and off. I have it write to a

csv file when the people logon and logoff. Twice I have noticed that the

csv file appears to have had a bunch of records deleted.

 

For example: I started the logon logoff events on January 8 and on January

10th I looked at a copy of the file so as not to disturb the original and

all it held was January 10th information. What could have happened to the

the information from the 8th or 9th?

 

The batch file is written as follows:

 

echo log-off script: log-off From: %computername%, User name: %username%,

Login Date: %Date%, Login Time: %Time%>>\\servername\share\logon-off.csv

 

I don't think there is anything written in that batch file that would delete

the prior days records is there?? Why would the information get deleted?

 

Thanks.

  • Replies 6
  • Created
  • Last Reply

Popular Days

Guest Pegasus \(MVP\)
Posted

Re: batch files and writing to csv file

 

 

"GMC" <gcoleman@legalassist.oops.org> wrote in message

news:%23KbD83IVIHA.5164@TK2MSFTNGP03.phx.gbl...

> Hello,

>

> I have logon and logoff batch files that I wrote and applied to a group

> policy to find out when people are logging on and off. I have it write to

> a

> csv file when the people logon and logoff. Twice I have noticed that the

> csv file appears to have had a bunch of records deleted.

>

> For example: I started the logon logoff events on January 8 and on January

> 10th I looked at a copy of the file so as not to disturb the original and

> all it held was January 10th information. What could have happened to the

> the information from the 8th or 9th?

>

> The batch file is written as follows:

>

> echo log-off script: log-off From: %computername%, User name: %username%,

> Login Date: %Date%, Login Time: %Time%>>\\servername\share\logon-off.csv

>

> I don't think there is anything written in that batch file that would

> delete

> the prior days records is there?? Why would the information get deleted?

>

> Thanks.

 

This could happen when two users try to write to the same

file at the same time. To avoid this, you could code like so:

 

echo log-off script: log-off From: %computername% . . .

\\servername\share\%ComputerName%.log

 

At the end of each day you get the Task Scheduler on your

server to run this batch file:

 

@echo off

cd /d "D:\Logs"

for %%a in (*.log) do type "%%a" >> logon-off.csv

del *.log

Posted

Re: batch files and writing to csv file

 

So it would help if I made a log file somehow for each person?

Guest Pegasus \(MVP\)
Posted

Re: batch files and writing to csv file

 

 

"GMC" <gcoleman@oopslegalassist.org> wrote in message

news:%23y0%23fTKVIHA.1168@TK2MSFTNGP02.phx.gbl...

> So it would help if I made a log file somehow for each person?

>

>

 

You could, but making a log file for each machine, as in

the example I gave you, is safer. It is possible that the

same account is used at two machines at the same time

(by two different persons) but it is not possible for one

machine to log on twice at the exact same time.

Posted

Re: batch files and writing to csv file

 

OK, I see. What does this do?

 

@echo off

cd /d "D:\Logs"

for %%a in (*.log) do type "%%a" >> logon-off.csv

del *.log

Guest Pegasus \(MVP\)
Posted

Re: batch files and writing to csv file

 

 

"GMC" <gcoleman@oopslegalassist.org> wrote in message

news:excBfjKVIHA.4364@TK2MSFTNGP02.phx.gbl...

> OK, I see. What does this do?

>

> @echo off

> cd /d "D:\Logs"

> for %%a in (*.log) do type "%%a" >> logon-off.csv

> del *.log

>

 

It scoops up the various log files and appends them

to logon-off.csv. Which part is unclear?

Posted

Re: batch files and writing to csv file

 

Ha! For me it was all unclear. You have explained well. I understand now,

thank you.


×
×
  • Create New...