Topic
3 replies Latest Post - ‏2013-10-03T12:24:50Z by brad_awg
awg_brad
awg_brad
10 Posts
ACCEPTED ANSWER

Pinned topic Identifying Server, Instance, and Database when running an Executable/Shell Script

‏2013-05-24T18:40:12Z |

Trying to determine the best way to identify the Server/Hostname, the DB2 instance, and the database name when I run an executable/shell script.  I assume that the requirement to select a database to run a job should then provide all these components but can't figure out how to access them.  The goal is to write one script which can run for multiple databases on multiple servers/instances.

We're running DB2 v10.1 on AIX with Data Studio v3.2, DSWeb Core Services v3.2.  (Web Console splash screen says v3.1).

Any help would be greatly appreciated, thanks!

  • AndreS
    AndreS
    2 Posts
    ACCEPTED ANSWER

    Re: Identifying Server, Instance, and Database when running an Executable/Shell Script

    ‏2013-05-27T03:42:50Z  in response to awg_brad

    Not sure if the question is Data Studio specific, and I am not sure what you are specifically looking for, but maybe the following will point you in the right direction. From your OS shell and therefore from any shell script you can:

    - Use db2ilist to list all instances on a server.

    - Use something like the following command to grab all instance databases, this must be run with the instance db2profile loaded:

               db2 list database directory | awk '{FS="\n";RS=""} /Indirect/ {print $2}' | awk '{print $4}'

    - Get the server/host with uname -a

    • awg_brad
      awg_brad
      10 Posts
      ACCEPTED ANSWER

      Re: Identifying Server, Instance, and Database when running an Executable/Shell Script

      ‏2013-05-28T15:10:05Z  in response to AndreS

      Sorry, the original question could have been more clearly stated.

      I'm using Web Console v3.2 to manage scheduled tasks on DB2/AIX v10.1.  Scheduling a backup which uses DB2/CLP works great for multiple databases but scheduling a Kornshell script for backup file cleanup doesn't seem to provide a method of passing the database, instance, or server name through to the script even though selecting a database is a requirement of scheduling the script.  I only want to clean up the old backup for a specific database after a successful new backup has been created.  I don't want to clean up any other backups from other databases for that same instance.  As a result, I need to know the database name tied to this particular scheduled task at run time.

      • brad_awg
        brad_awg
        3 Posts
        ACCEPTED ANSWER

        Re: Identifying Server, Instance, and Database when running an Executable/Shell Script

        ‏2013-10-03T12:24:50Z  in response to awg_brad

        This issue was resolved by using some undocumented environment variables set at script runtime.  Below is the information I was provided.

        • DSWEB_LOGGEDIN_USER  :  The userID used to run the script (also the ssh userID)
        • DSWEB_DATABASE_PROFILENAME:  The database profile name  (the 'name' associated with the database when it is registered - in the Databases page). Note this is not the physical database name  - its the unique identifier associated with the database. 
        • DSWEB_JOB_ID:   This Job's unique ID
        • DSWEB_JOB_NAME:   The name (label)  provided by the user for this job
        • DSWEB_ALERT_ID:  When this job is fired as an alert action - this variable represents that alert's ID.
        • DSWEB_ALERT_TYPE_NAME:  The type of alert that was created
        • DSWEB_ALERT_DETAIL:  Some key details/abstract about the alert - similar to what is seen when an alert notification email is sent out. 

        Additionally, it required some creative naming of the databases.  I chose SERVERNAME.instancename.DATABASENAME.  I then parse this value for whatever information I need.