Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Jul 2006
    Location
    Pune , India
    Posts
    433

    Exclamation Unanswered: dos scripits for db2

    Windows 2000

    we usually run dos scripits for db2 using 2 file .
    1st one intializeses the db2cmd env. for other

    first file --> Click_me.bat
    content--> db2cmd .\1.bat

    second file -->1.bat
    content--> db2 connect to sample ...
    db2 create table..
    db2 insert into..
    db2 connect reset ..

    is it possible to just create and call only 1 file which also initializes the db2cmd environment in windows .
    Rahul Singh
    Certified DB2 9 DBA / Application Developer

  2. #2
    Join Date
    Jun 2006
    Posts
    471

    script

    you could call db2cmd with argument xxxx
    when db2 window is opened the xxxx script/commands will be executed
    should be a bat/cmd file with db2 commands or db2 -tvf fff
    Best Regards, Guy Przytula
    DB2 UDB LUW certified V6/7/8

  3. #3
    Join Date
    Jul 2006
    Location
    Pune , India
    Posts
    433
    Thanks Guy Przytula
    But what i need is to provide a single batch file to my clients so that just a double click on it will do all the things.
    Atpresent i have to provide 2 files as you explained in ur post.
    Rahul Singh
    Certified DB2 9 DBA / Application Developer

  4. #4
    Join Date
    Jan 2003
    Posts
    1,605
    rahul_s80,
    on Windows there has to be two files on Unix/Linux there can be only one. I hate it too, but thats the way it is.

  5. #5
    Join Date
    Jan 2003
    Posts
    1,605
    rahul_s80,
    I have figured out one solution to have ONLY ONE batch file to execute more then one DB2 command. Save bellow code into batch file and execute it.
    Code:
    Please see code few posts bellow...
    Note: Don't change "Initialization of DB2 environment on Windows" section. Only change "Run db2 commands" section.

    Hope this helps,
    Grofaty
    Last edited by grofaty; 02-28-07 at 08:17.

  6. #6
    Join Date
    Jul 2006
    Location
    Pune , India
    Posts
    433
    Hey Grofaty
    Thanks... good work....
    Rahul Singh
    Certified DB2 9 DBA / Application Developer

  7. #7
    Join Date
    Jan 2003
    Posts
    1,605
    rahul_s80,
    just one more note: path in DB2PATH variable is db2 installation path. The default is C:\Program Files\IBM\SQLLIB. If you installed the db2 software in any other directory or drive you need to change the path.

    This code should work on Windows XP SP2. I don't know if this works on older versions like Windows 98. You should try this out by yourself. I just don't have any Win98 computer anymore.

    Hope this helps,
    Grofaty

  8. #8
    Join Date
    Jan 2003
    Posts
    1,605
    Hi,
    I have changed the code. This code should work also if multiple batch files are executed at the same time e.g. scheduled at Windows (It uses timestamp and file name data in temporally directory). This script also gets the DB2PATH string from DB2 configuration, so there is no need of changing any data in "Initialization" section if DB2 is not installed on default path.

    Code:
    rem ---------------------------------------------------------
    rem -- EXECUTE DB2 COMMANDS FROM ONE BATCH FILE
    rem -- Script written by Grofaty. E-mail: grofaty@hotmail.com
    rem -- Tested on DB2 v8.2 for Windows XP
    rem -- Written at: 2007-02-28
    rem ---------------------------------------------------------
    rem
    rem ---------------------------------------------------------
    rem -- Initialization of DB2 environment on Windows
    rem ---------------------------------------------------------
    set timestamp=%date:~4% %time%
    set timestamp=%timestamp::=%
    set timestamp=%timestamp:.=%
    set timestamp=%timestamp:,=%
    set timestamp=%timestamp: =%
    set DB2ClpFile=%temp%\DB2Clp%timestamp%%~nx0
    set DB2PathFile=%temp%\DB2Path%timestamp%%~nx0
    set DB2File=%temp%\DB2File%timestamp%%~nx0
    echo echo %%DB2PATH%% ^> %DB2PathFile% > %DB2File%
    echo echo %%DB2CLP%% ^> %DB2ClpFile% >> %DB2File%
    call db2cmd /w /i /c %DB2File%
    for /f "tokens=*" %%i in ('type %DB2PathFile%') do (set DB2PathVar=%%i)
    set DB2PATH=%DB2PathVar%
    for /f "tokens=1" %%i in ('type %DB2ClpFile%') do (set DB2ClpVar=%%i)
    set DB2CLP=%DB2ClpVar%
    del %DB2ClpFile%
    del %DB2PathFile%
    del %DB2File%
    set DB2ClpVar=
    set DB2PathVar=
    set DB2ClpFile=
    set DB2PathFile=
    set DB2File=
    
    rem -------------------------------------------------------
    rem -- Run db2 commands
    rem -------------------------------------------------------
    
    db2 connect to sample
    db2 select * from sysibm.sysdummy1
    db2 connect reset
    Note: Don't change "Initialization of DB2 environment on Windows" section. Only change "Run db2 commands" section. Save file with 'bat' extension and execute it.

    Hope this helps,
    Grofaty
    Last edited by grofaty; 03-01-07 at 08:23.

  9. #9
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    I think there may be an easier way of doing this. These are the entire contents of a test batch file that can be called directly from Windows (e.g. by double-clicking).
    Code:
    @echo off
    rem If we're not called from DB2CLP, call ourselves again
    if "%DB2CLP%" == "" db2cmd /c /i /w %0 %* & goto :eof
    
    rem Now the real stuff
    db2 connect to MYDB
    db2 select * from sysibm.sysdummy1
    db2 connect reset
    rem etc.
    The line in red is the only one that needs to be added. What it does is check if the DB2 command line environment is initialized and if not, calls the same batch file again with db2cmd.exe and then exits.
    ---
    "It does not work" is not a valid problem statement.

  10. #10
    Join Date
    Jan 2003
    Posts
    1,605
    n_i,
    that is an excellent solution! I really admire if someone makes some code more simple. Thanks!

  11. #11
    Join Date
    Jan 2003
    Posts
    1,605
    Hi,
    just to let you know: above script (batch file) works only if there is stored in directory without spaces.

    For example in today my sample I have stored it on Windows desktop and it doesn't work. Work-around is to store batch file in directory without spaces and create shortcut on Windows desktop.

    Hope this helps,
    Grofaty

  12. #12
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Another workaround would be to put double quotes around %0:
    Code:
    if "%DB2CLP%" == "" db2cmd /c /i /w "%0" %* & goto :eof
    ---
    "It does not work" is not a valid problem statement.

  13. #13
    Join Date
    Jul 2006
    Location
    Pune , India
    Posts
    433
    In some other forum i found this for V9
    SET DB2CLP=**$$**
    Rahul Singh
    Certified DB2 9 DBA / Application Developer

  14. #14
    Join Date
    Jan 2003
    Posts
    1,605
    rahul_s80,
    I have tried it on DB2/Windows v8.2 FP9 and this is not working. It looks like new solution...
    Regards,
    Grofaty

  15. #15
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    SET DB2CLP=**$$** had to be added to profile if cygwin was being used - otherwise we had a problem with db2 commands in a window (connection lost..)
    see the apar http://www-1.ibm.com/support/docview...id=swg1JR26025
    Best Regards, Guy Przytula
    Database Software Consultant
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

Posting Permissions

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