Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2012
    Posts
    177

    Unanswered: Shell script in db2

    Hi all,

    In our setup db2 V9.7 with fixpack 4

    Question over the shell script.

    Shell script written to connect the database and check the tablespace details.

    Script:
    ------
    filename="/tisdev/temp/tablespacemonitorfile"
    current_date=`date "+%Y-%m-%d-%H"`
    filename=$filename$current_date.txt
    db2 connect to TIS_DWHT > /tisdev/temp/connect_status.txt
    db2 "select TBSP_NAME, TBSP_ID, TBSP_STATE, TBSP_USED_PAGES, TBSP_FREE_PAGES, TBSP_USABLE_PAGES, TBSP_TOTAL_PAGES from table(mon_get_tablespace('',-2)) as t" > $filename

    Script executed successfully by manual running.

    Script automated to crontab but the script is executed but I am not getting the output.

    [db2inst1@XXXX ~]$ crontab -l
    56 19 8 5 * sh tablespace_monitoring_script.sh

    0 May 8 20:47 tablespacemonitorfile2013-05-08-20.log
    0 May 8 20:47 connect_status.txt

    How to automated the script and how to excuted the script successfully.

    Thanks,
    laxman.

  2. #2
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    this is a real basic : (handled many times in forum)
    when executed from crontab : environment is not set --> path is not defined....
    add to script.....
    . /home/db2inst1/sqllib/db2profile (with the correct location ..)
    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

  3. #3
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    Quote Originally Posted by przytula_guy View Post
    this is a real basic : (handled many times in forum)
    when executed from crontab : environment is not set --> path is not defined....
    add to script.....
    . /home/db2inst1/sqllib/db2profile (with the correct location ..)
    In most cases, if the cron script is run as instance owner, you can use:
    . $HOME/sqllib/db2profile
    This has the advantage of not needing to know the exact path for each instance.
    M. A. Feldman
    IBM Certified DBA on DB2 for Linux, UNIX, and Windows
    IBM Certified DBA on DB2 for z/OS and OS/390

  4. #4
    Join Date
    May 2013
    Posts
    5
    Hi
    I am using the command
    db2look -d dbname -l -z schema -t table| grep -ip tablespace > tbs.ddl
    this command is working fine when i use it in command prompt and i am able to see the tablespace ddl in tbs.ddl
    But when I put the same command in a shell script, tbs.ddl is an empty file.
    I am preparing a shell.script which has this command as its code.... please help me in this

    Thanks in advance,
    Rupesh

  5. #5
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    Quote Originally Posted by 333rupesh View Post
    Hi
    I am using the command
    db2look -d dbname -l -z schema -t table| grep -ip tablespace > tbs.ddl
    this command is working fine when i use it in command prompt and i am able to see the tablespace ddl in tbs.ddl
    But when I put the same command in a shell script, tbs.ddl is an empty file.
    I am preparing a shell.script which has this command as its code.... please help me in this

    Thanks in advance,
    Rupesh
    Please post the exact contents of your shell script.
    M. A. Feldman
    IBM Certified DBA on DB2 for Linux, UNIX, and Windows
    IBM Certified DBA on DB2 for z/OS and OS/390

  6. #6
    Join Date
    May 2013
    Posts
    5

    db2look -l

    #!/bin/bash
    dbname=$1
    schema=$2
    table=$3
    tbspace=xxxxx_201305
    datatbsmon=201305
    newmon=201306
    db2look -d $dbname -l -z $schema - t $table|grep -ip $tbspace|sed 's/'$datatbsmon'/'$newmon'/' > tbs.ddl

    the tablespace names are like xxxxx_201305

    Thanks,
    Rupesh.
    Last edited by 333rupesh; 05-11-13 at 07:54. Reason: correction

Posting Permissions

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