Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2010
    Location
    Singapore
    Posts
    197

    Question Unanswered: Db2 Batch script doubt

    Hi All,

    I am using a simple batch script. getting error saying db2 is not initialized

    @echo off
    set UNIXUTIL=unixutil

    set DB2CLP=%db2clp%
    set DB2INSTANCE=%DB2INSTANCE%

    FOR /F %%G in (db_names.txt) DO (
    echo %%G >> 1.txt
    db2 -v "connect to %%G" >> 1.txt
    db2 -v "select count(*) from syscat.tables " >> 1.txt
    )


    Error :

    TEST
    DB21061E Command line environment not initialized.
    DB21061E Command line environment not initialized.
    - Ananth
    DB2 DBA LUW
    "coming second, just means you are the first loser"

  2. #2
    Join Date
    Apr 2012
    Posts
    1,034
    Provided Answers: 18
    Re: DB21061E Command line environment not initialized


    This is a frequently asked question , solutions are widely visible ...

    The first line of your batch file could look like this:

    @if "%DB2CLP%"=="" db2cmd /c /i /w "%0" %* && goto :EOF

    It's not wise to explicitly set DB2CLP. Let the system manage that variable.

    Best to add error checks to your batch file also, for example:

    db2 -v "connect to ...."
    if errorlevel 1 (@echo Failed to connect to database && goto :EOF)

  3. #3
    Join Date
    Aug 2010
    Location
    Singapore
    Posts
    197
    Thanks it worked, I did try my google skils, wasnt helpful.
    - Ananth
    DB2 DBA LUW
    "coming second, just means you are the first loser"

  4. #4
    Join Date
    Jul 2013
    Location
    Moscow, Russia
    Posts
    666
    Provided Answers: 55
    Hi,

    another option might be to set once the following OS environment variable exactly as is:
    DB2CLP=**$$**
    You don't have to use db2cmd afterwards. Just run your batches from the OS command prompt directly.
    Can be useful, for example, if you want to have an ability to run your db2 commands remotely with Cygwin ssh server on your Windows box.
    Regards,
    Mark.

  5. #5
    Join Date
    Aug 2010
    Location
    Singapore
    Posts
    197
    Thanks all, I finally wrote a script.
    - Ananth
    DB2 DBA LUW
    "coming second, just means you are the first loser"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •