none
Need to execute interactive job generating log file having year, month, day and time

    Question

  • Need to execute interactive job generating log file having year, month, day and time.

    Something like:

    myscript.bat > LOG-YYYYMMDDHHMM.txt

    Since I will have the script executing several times per day, the "time" part of the log file is critical, to be able to tell what time during the day the job executed.

    How can that be done easily? I looked at some of the suggested examples, but none were close enough to the above.

    I don't want PowerShell, just basic Windows command-line stuff.

    thank you.


    sj.

    Tuesday, October 15, 2013 3:29 AM

Answers

  • Okay, here is what I do - not perfect, but it works:

    @echo off
    set hr=%time:~0,2%
    set hr=%hr: =0%
    cscript.exe c:\scripts\agepwd.vbs > c:\scripts\agepwd-LOG-%date:~10%%date:~4,2%%date:~7,2%%hr%%time:~3,2%.txt

    Above gives output file name like: agepwd-LOG-201310140733.txt (this would be a script that ran Oct 14, 2013 at 07:33 am.

    Hope this was helpful. Please remember to Mark as Answer (and VOTE!) - It's okay to mark Multiple answers, if more than one answer helped solve your issue. Thanks!


    tnjman

    • Marked as answer by MisterJenks Tuesday, October 15, 2013 4:09 AM
    Tuesday, October 15, 2013 3:45 AM

All replies

  • Okay, here is what I do - not perfect, but it works:

    @echo off
    set hr=%time:~0,2%
    set hr=%hr: =0%
    cscript.exe c:\scripts\agepwd.vbs > c:\scripts\agepwd-LOG-%date:~10%%date:~4,2%%date:~7,2%%hr%%time:~3,2%.txt

    Above gives output file name like: agepwd-LOG-201310140733.txt (this would be a script that ran Oct 14, 2013 at 07:33 am.

    Hope this was helpful. Please remember to Mark as Answer (and VOTE!) - It's okay to mark Multiple answers, if more than one answer helped solve your issue. Thanks!


    tnjman

    • Marked as answer by MisterJenks Tuesday, October 15, 2013 4:09 AM
    Tuesday, October 15, 2013 3:45 AM
  • Thank you - I just tested your logic, and it works great for me. This is just what I needed.

    Grateful.


    sj.

    Tuesday, October 15, 2013 4:09 AM