Scripts Thread, script time stamp help in Coding and Web Development; I am running the following script on the server from a gpo to log user activity, I copied the script ...
-
27th February 2008, 06:35 AM #1 script time stamp help
I am running the following script on the server from a gpo to log user activity, I copied the script from this site and adjusted to suit our domain.
However I have issues with the date function of the script any help would be appreciated.
Copy of output file for Geo_office
022008,1334,yneeve
022008,1515,yneeve
022008,1521,yneeve
022008,0901,yneeve
022008,0500,Administrator
02272008 ,0502 AM,Administrator
022008,0505,Administrator
022008,0505,Administrator
The date is not correct on the first 5 entries, if I log on and to the machine and change the date settings to English united states all is well as seen on line 5. This is qualified by lines 7 and 8 not working once I have changed the date settings back to uk.
What is the correct format for the fist 2 lines of the script to extract the correct time from the local computer?
Audit Script
for /f "tokens=1,2,3* delims=/ " %%a in ('date /t') do set date=%%b%%c%%d
for /f "tokens=1,2 delims=:" %%a in ('time /t') do set time=%%a%%b
echo %date%,%time%,%username% >> \\server2\ipstats\logs\computer\%computername%.txt
echo %date%,%time%,%computername% >> \\server2\ipstats\logs\user\%username%.txt
echo %logonserver% >> \\server2\ipstats\logs\logon\%computername%.txt
echo %time% %username% > \\server2\ipstats\logs\users\%computername%.txt
ipconfig | find "IP Address" > \\server2\ipstats\logs\ips\%computername%.txt
ipconfig | find "IP Address" > \\server2\ipstats\logs\ips\%computername%.txt
Kind Regards Mike
-
-
IDG Tech News
-
27th February 2008, 10:27 AM #2 could be wrong but I don't think you can deal with this in a batch file. I think the "time" command will always show what it thinks is local time so if some of your machines are configured US and some UK then you will get it mixed up. The "for /f" bit is telling it to split the string at the "/" but has no way of knowing if it's getting 27/02/2008, 02/27/2008 etc.
I always do this kind of thing in vbscript and strip out the day, month, year and then stick them back together appropriately:
sDate=year(now) & right("0" & month(now),2) & right("0" & day(now),2)
- replace "now" with a variable for the relevant date if you're not interested in the current date/time. This way you always end up with yyyymmdd and it makes it easier to process!
-
-
27th February 2008, 06:54 PM #3 Great thanx will sort that out, i will use vb thanx for the advice will keep you posted.
regards Mike
-
-
28th February 2008, 07:22 PM #4
great thanx for putting me in the right direction, now using vb script below works great, had to mess around a bit not being a natural at scripting, once again thank you!
call logger
public sub logger()
dim filesys, filetxt, uservar
set WshNetwork = Createobject("WScript.Network")
Set objNetwork = Wscript.CreateObject("Wscript.Network")
Set filesys = CreateObject("Scripting.FileSystemObject")
on error resume next
computername = objNetwork.ComputerName
Const ForReading = 1, ForWriting = 2, ForAppending = 8
uservar = objNetwork.UserName
Set filetxt = filesys.OpenTextFile("\\server2\ipstats\logs\compu ter\" & computername & ".txt", ForAppending, True)
filetxt.WriteLine(Date & ": " & Time & ": " & uservar & " logged on to " & computername)
filetxt.Close
Set filetxt = filesys.OpenTextFile("\\server2\ipstats\logs\user\ " & uservar & ".txt", ForAppending, True)
filetxt.WriteLine(Date & ": " & Time & ": " & uservar & " logged on to " & computername)
filetxt.Close
end sub
-
Thanks to Mike-j from:
Zaphyr (1st February 2010)
SHARE:
Similar Threads
-
By Samson in forum Scripts
Replies: 3
Last Post: 4th September 2007, 07:40 AM
-
By gwendes in forum General Chat
Replies: 45
Last Post: 10th February 2007, 06:38 PM
-
By sidewinder in forum Windows
Replies: 4
Last Post: 15th December 2006, 01:14 PM
-
By ITWombat in forum Web Development
Replies: 6
Last Post: 2nd July 2006, 07:36 PM
-
By NetworkGeezer in forum Windows
Replies: 7
Last Post: 1st June 2006, 05:13 PM
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules