+ Post New Thread
Results 1 to 4 of 4
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 ...
  1. #1
    Mike-j's Avatar
    Join Date
    Feb 2008
    Posts
    15
    Thank Post
    0
    Thanked 2 Times in 2 Posts
    Rep Power
    14

    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

  2. #2

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,156
    Thank Post
    116
    Thanked 529 Times in 452 Posts
    Blog Entries
    2
    Rep Power
    124
    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!

  3. #3
    Mike-j's Avatar
    Join Date
    Feb 2008
    Posts
    15
    Thank Post
    0
    Thanked 2 Times in 2 Posts
    Rep Power
    14
    Great thanx will sort that out, i will use vb thanx for the advice will keep you posted.

    regards Mike

  4. #4
    Mike-j's Avatar
    Join Date
    Feb 2008
    Posts
    15
    Thank Post
    0
    Thanked 2 Times in 2 Posts
    Rep Power
    14
    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

  5. Thanks to Mike-j from:

    Zaphyr (1st February 2010)

SHARE:
+ Post New Thread

Similar Threads

  1. VBS File takes long time to load 1st time?
    By Samson in forum Scripts
    Replies: 3
    Last Post: 4th September 2007, 07:40 AM
  2. Who works term time only? How many full time?
    By gwendes in forum General Chat
    Replies: 45
    Last Post: 10th February 2007, 05:38 PM
  3. Replies: 4
    Last Post: 15th December 2006, 12:14 PM
  4. Format of Squid log time stamp
    By ITWombat in forum Web Development
    Replies: 6
    Last Post: 2nd July 2006, 07:36 PM
  5. Startup script time-out gotcha aargh!!
    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
  •