locked
Log File from batch file RRS feed

  • Question

  • Hi guys,

    I'm running a batch file which moves some files and runs multiple vbscripts.  I've been trying to create a log file that shows everything in the command windows as i'll be scheduling the job but I can't get it to work. I wanted to run the batch file and get a log file which would show if there was any errors completing the vbscripts successfully.

    My batch file looks like this..

    @echo on
    TITLE Validation.bat


    echo y | del E:\Automation\Ondemand\exports\Validation\PNL\*.*

     Going to run SQL queries
     cscript E:\Automation\VBScript\Final\PNL_Gaap_Query.vbs
     cscript E:\Automation\VBScript\Final\PNL_IFRS_Query.vbs
     cscript E:\Automation\VBScript\Final\Units_Query.vbs
     cscript E:\Automation\VBScript\Final\Units_Full_Query.vbs
     cscript E:\Automation\VBScript\Final\Oracle_Gaap_Full_Query.vbs
     cscript E:\Automation\VBScript\Final\Oracle_IFRS_Full_Query.vbs

     

    Running report from Hyperion
    essmsh E:\Automation\Ondemand\On_Demand_Actuals_PNL_Reports.msh


    cscript E:\Automation\VBScript\Final\Validate_Units_YTD.vbs
    cscript E:\Automation\VBScript\Final\Validate_Units_QTD.vbs
    cscript E:\Automation\VBScript\Final\Validate_PNL_GAAP_QTD.vbs
    cscript E:\Automation\VBScript\Final\Validate_PNL_GAAP_YTD.vbs
    cscript E:\Automation\VBScript\Final\Validate_PNL_IFRS_QTD.vbs
    cscript E:\Automation\VBScript\Final\Validate_PNL_IFRS_YTD.vbs


     

    Tuesday, February 1, 2011 12:38 PM

Answers

  • yes, whatever you echo in your script will be recorded here including errors, so your script should have them.

    for errors, you should have handled it in the vbscript itself.

    for example:

    if err.number > 0 then

     wscript.echo err.description & vbtab & err.number

    err.clear

    else

    end if

    i suggset doing the loggin in the script itself instead of doing it like this. which gives you more control


    Thiyagu | MCTS/MCITP - Exchange 2007 | MCSE 2003[Messaging] | http://www.myExchangeWorld.com. This posting is provided "AS IS" with no warranties, and confers no rights.

    • Marked as answer by CreativeJunkie Tuesday, February 1, 2011 1:57 PM
    • Edited by Thiyagu14 Tuesday, February 1, 2011 1:58 PM update
    Tuesday, February 1, 2011 1:56 PM

All replies

  • why not put a " >> logfile.txt" at end of the cscript lines? to record the output of the script?
    Thiyagu | MCTS/MCITP - Exchange 2007 | MCSE 2003[Messaging] | http://www.myExchangeWorld.com. This posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, February 1, 2011 12:51 PM
  • Hey Thiyagu,

    I have been trying that and all I get is a log file with:

    Microsoft (R) Windows Script Host Version 5.6
    Copyright (C) Microsoft Corporation 1996-2001. All rights reserved..

    Thanks

    • Proposed as answer by majortargets Thursday, March 8, 2018 5:39 PM
    Tuesday, February 1, 2011 12:58 PM
  • at any line by typo did you give just a ">" becoz this will overwrite the file whatever was tehre, so you should use ">>" this will append to the file.

     

    i just tested with some sample .vbs file where i just echo some value and here is the output:

    ----------------------

    Microsoft (R) Windows Script Host Version 5.7
    Copyright (C) Microsoft Corporation. All rights reserved.

    World


    Microsoft (R) Windows Script Host Version 5.7
    Copyright (C) Microsoft Corporation. All rights reserved.

    Hello World

    ---------------------------

     


    Thiyagu | MCTS/MCITP - Exchange 2007 | MCSE 2003[Messaging] | http://www.myExchangeWorld.com. This posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, February 1, 2011 1:11 PM
  • another thought is that it might create the files in the folder where you are running the script from,

    if  you are running the script or bat from c:\ , it will create it there, can you search ur server for the log file name to see if it created some where else.


    Thiyagu | MCTS/MCITP - Exchange 2007 | MCSE 2003[Messaging] | http://www.myExchangeWorld.com. This posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, February 1, 2011 1:12 PM
  • Strange as I'm getting the log file but the result is:

     

    Microsoft (R) Windows Script Host Version 5.6
    Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

    Microsoft (R) Windows Script Host Version 5.6
    Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

    Microsoft (R) Windows Script Host Version 5.6
    Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

    the lines I'm using are like:

    cscript E:\Automation\VBScript\Final\Validate_Units_YTD.vbs >> E:\Automation\Ondemand\logs\validation.txt

    However, I need to then add some echo commands in the vbscript right?  So throughout the vbscript I need to add echo log commands and they will be added here?  How come I don't get any results in this log that the above vbscript ran?

     

    Tuesday, February 1, 2011 1:53 PM
  • yes, whatever you echo in your script will be recorded here including errors, so your script should have them.

    for errors, you should have handled it in the vbscript itself.

    for example:

    if err.number > 0 then

     wscript.echo err.description & vbtab & err.number

    err.clear

    else

    end if

    i suggset doing the loggin in the script itself instead of doing it like this. which gives you more control


    Thiyagu | MCTS/MCITP - Exchange 2007 | MCSE 2003[Messaging] | http://www.myExchangeWorld.com. This posting is provided "AS IS" with no warranties, and confers no rights.

    • Marked as answer by CreativeJunkie Tuesday, February 1, 2011 1:57 PM
    • Edited by Thiyagu14 Tuesday, February 1, 2011 1:58 PM update
    Tuesday, February 1, 2011 1:56 PM
  • The output of all of the scripts being executed can be redirected by redirecting the output of the batch file that is being executed, as in ...

    C:\somewhere>Validation > logfile.txt

    Also, the header lines from Cscript can be suppressed with its //nologo switch or it can be made universal using ...

      cscript //nologo //s

    Of course it can be done as in a toggle sense at the start of the routine and restored at the end.

    Come to think of it the redirection can be instituted as a recursive call, something like this ...

    @echo off
     TITLE Validation.bat

    REM Redirect all output to the named log file
     if not "%~1"=="2nd" (%0 2nd %*  1> mylogfile.txt 2>&1)

     shift

     del /q E:\Automation\Ondemand\exports\Validation\PNL\*.*

    REM Turn Cscript logos off
     cscript //nologo //s > nul

    REM Going to run SQL queries
     pushd E:\Automation\VBScript\Final
     cscript PNL_Gaap_Query.vbs
     cscript PNL_IFRS_Query.vbs
     cscript Units_Query.vbs
     cscript Units_Full_Query.vbs
     cscript Oracle_Gaap_Full_Query.vbs
     cscript Oracle_IFRS_Full_Query.vbs

    REM Running report from Hyperion
     essmsh E:\Automation\Ondemand\On_Demand_Actuals_PNL_Reports.msh

     cscript Validate_Units_YTD.vbs
     cscript Validate_Units_QTD.vbs
     cscript Validate_PNL_GAAP_QTD.vbs
     cscript Validate_PNL_GAAP_YTD.vbs
     cscript Validate_PNL_IFRS_QTD.vbs
     cscript Validate_PNL_IFRS_YTD.vbs
     popd

    REM Restore Cscript logos
     cscript //logo //s > nul

    Of course, if there is no output from the scripts to the console, there will be nothing in the log file other than the results of the DEL statement.


    Tom Lavedas
    Tuesday, February 1, 2011 2:00 PM