Variables for scripts for jobs and user-defined alerts

You can use predefined variables in scripts that you specify for jobs or user-defined alerts. For example, you can create a script that includes a variable DSWEB_DATABASE_NAME that resolves to the physical database name.
To add variables to the script, wrap each variable with ${ }; for example:
${DSWEB_DATABASE_PROFILENAME}

Variables for both job manager and user-defined scripts

The variables in the following table can be used in any job manager and user-defined alert script. These variables represent values that are identified with the alert, such as the database name and job ID.

Table 1. Variables that can be used in job manager and user-defined scripts
Variable Value returned
DSWEB_DATABASE_NAME The physical database name.
DSWEB_DATABASE_PROFILENAME The name that is associated with the database when it is created on the databases page.

This value is not the physical database name, but the unique identifier that is associated with the database.

DSWEB_INSTANCE_NAME The DB2 instance name.
DSWEB_JOB_ID The job that ran the script’s unique ID.
DSWEB_JOB_NAME The name or label that you used for the current job.
DSWEB_LOGGEDIN_USER The user ID that is used to run the script. This user ID can also be the SSH user ID.

Variables for job manager scripts only

The variables in Table 2 can be used only in job manager scripts. These variables are defined only when they are triggered from the Alert Action feature.

Table 2. Variables that can be used only in job manager scripts
Variable Value returned
DSWEB_ALERT_DETAIL Key details or abstract about the alert.
DSWEB_ALERT_ID The alert ID for the specified alert action.
DSWEB_ALERT_TYPE_NAME The type of alert such as database status.

Extract and schedule audit records from a set of databases

In this example, the enterprise DBA team at Great Outdoor Company is responsible for managing hundreds of databases. One of their requirements is to extract audit records from a set of databases at regular intervals (for example, weekly) and then FTP the delimited file to their central server. From that central server, a custom application collates the audit information. Policy compliance and user access validation is reviewed, and any issues are flagged for resolution.

The DBA team develops a script to extract audit records with the SYSPROC.AUDIT_DELIM_EXTRACT stored procedure. SYSPROC.AUDIT_DELIM_EXTRACT is accessible from /mnt/dba/scripts/extractaudit.sh in all of their Linux and UNIX systems. SYSPROC.AUDIT_DELIM_EXTRACT uses DB2 commands and other utilities to extract audit records and copy those records to the central server. The DBA team’s existing generic script expects the database name as an argument when started. The DBA team wants to create a script that extracts the database name. From the job manager, they can schedule the script to run at regular intervals to automate the extraction of the database name.

To add variables to a script, wrap each variable with ${ }; for example:
${DSWEB_DATABASE_PROFILENAME}
echo ==========================================
echo TRACE: Job name is '${DSWEB_JOB_NAME}', Job ID is '${DSWEB_JOB_ID}'
echo TRACE: Job is being run against Database Profile '${DSWEB_DATABASE_PROFILENAME}' with userID: '${DSWEB_LOGGEDIN_USER}'
echo TRACE: The database name is '${DSWEB_DATABASE_NAME}'
echo ==========================================
/mnt/dba/scripts/extractaudit.sh ${DSWEB_DATABASE_NAME}

After the DBA runs the script, the DBA then tests the output against another database to confirm that the script invocation from the job is working as expected. The DBA switches to the History view and verifies that the script has run successfully by viewing the execution log. The DBA then creates a schedule in the Schedules section to run the job weekly. The DBA selects the set of databases and time. The DBA also chooses to create monthly schedules for those databases that needs this job to run only on a monthly basis.


Feedback