ADSM-L

Formatting select output AIX 3.1.2.40 3.1.2.6 Client

1999-11-24 13:51:46
Subject: Formatting select output AIX 3.1.2.40 3.1.2.6 Client
From: Bart Colbert <Bart.Colbert AT RAYONIER DOT COM>
Date: Wed, 24 Nov 1999 13:51:46 -0500
Since there is a lot of formatting questions related to AIX output here.

I am including some utilities.

Basic function calls:

[REPORTS THE VOLUMES INFORMATION FROM THE BKP_DLT_COPY1 STORAGE POOL]

adsm.mail.STORAGE_POOL_NAME.volumes.sh
     |
     adsm.mail.stgpool.volumes.sh STORAGE_POOL_NAME
          |
          adsm.select.parse

You will notice if you try to use the adsm.select.parse with some out puts
that I did not cover every contention, but for basic tape info it works
fine.

Thanks,
Bart Colbert
UNIX Sys Admin
Rayonier, Inc.
Bart.Colbert AT rayonier DOT com

-------8<--------SNIP---------->8-------
/***********************************************************************
/***********************************************************************
** adsm.select.parse.c: Formats stdin from a select statement         **
** passed by a shell script from adsm.                                **
** Written By: Bart G. Colbert 09/23/1999 ANSI C                      **
** Version 1.0                                                        **
** Revisions:                                                          **
**                                                                    **
** *) 09/27/1999 Bart G. Colbert V1.1                                 **
**    the _date functions return a date value and a timestamp.        **
**    the odd part about this is that the timestamp gets appended to  **
**    the display output and not in the order that the _date field    **
**    is located in the select statement. (I Give)???                 **
**    To make some accommodations for this, I have added a check that  **
**    looks at the existing field and checks for _date or _date,      **
**    in which case another field would follow. But due to the        **
**    time stamp being displayed in no particular order, I have the   **
**    print statement checking to see if its a time its printing.     **
**    Basically they have two different forms of fields that end with **
**    the word date, but _date is date space time where the space     **
**    is replaced by any fields specified after the _date in the      **
**    select. Current version is AIX ADSM V3.1.2.40                   **
**                                                                    **
** *) 09/29/1999 Bart G. Colbert V1.2                                 **
**    If a date has no data IE:last_write_date and has not been       **
**    Then awk will consider the next field as this one. Totally      **
**    trashes a table format. The other problem with the strange      **
**    date output is that is you use two fields such as               **
**    last_read_date, last_write_date then you will get the two date  **
**    columns followed by two time columns. Of course if you have any **
**    other fields as mentioned above then the two time columns are   **
**    appended to the display of any others. Conclusion is that none  **
**    of these parse facilities will handle two of those type of      **
**    dates. It is confusing to read in date1 date2 time1 time2       **
**    format. The requirement is that the _date field be placed as    **
**    the last field on the select statement. If the timestamp is not **
**    desired it can be left out of the awk $# vars.                  **
**                                                                    **
** *) 09/30/1999 Bart G. Colbert V1.3                                 **
**    SAPLOG2 Tapes are taken from a scratch tape in the IBM7331      **
**    Though they are assigned to the pool they are not assigned a    **
**    LOCATION. Pacing a location field counter and checking for the  **
**    token value to be equal to one of the locations, if this is not **
**    true then a value of UNKNOWN is used as a place holder.         **
**                                                                    **
***********************************************************************/

/*
 * RCS INFO
 */
static char _rcsid_adsm_select_parse[] = "@adsm.select.parse.c V1.3, Bart
G. Colbert ANSI C 09/30/1999.\n";

/*
 * INCLUDE STANDARD PREPROCESSOR HEADER FILES
 */
#include <stdio.h>
#include <string.h>

/*
 * BEGIN MAIN FUNCTION
 */
int main ( int argc, char *argv[] )
{

/*
 * INIT ANY LOCAL VARS
 */
char lnbuff[64384];
char *token;
int count_date, display_count, location_count, return_count, string_length;
unsigned BEGIN, END, DASH, START, COMPLETE;

/*
 * GRAB THE STANDARD INPUT IN ONE 64K CHUNK
 */
fgets ( lnbuff, 65384, stdin );

/*
 * TOKENIZE THE STRING OF INPUT DATA
 */
token = strtok ( lnbuff, " " );

/*
 * BEGIN DO WHILE TOKEN NE NULL
 */
do
{

/*
 * PARSE THE NEXT TOKEN FROM STRING
 */
token = strtok ( NULL, " " );

/*
 * IF THE TOKEN IS SELECT THEN SET BEGIN
 */
if ( strcmp ( token, "'select" ) == 0 ) {
     BEGIN=1;
     }

/*
 * BEGIN IF BEGIN IS SET
 */
if ( BEGIN == 1 ) {

     /*
      * CHECK FOR THE FIELD NAME ENDING WITH _date OR _date, AND INCREMENT
      * THE DISPLAY COUNT TO GET THE TIMESTAMP.
      * SEE REVISIONS NOTE ABOUT THE GARBAGE THAT ADSM IS DOING HERE. :(
      */
     if ( strlen(token) != NULL ) {
     if ( ((token[strlen(token)-1] == 'e')\
           && (token[strlen(token)-2] == 't') && (token[strlen(token)-3]
== 'a')\
           && (token[strlen(token)-4] == 'd') && (token[strlen(token)-5]
== '_'))\
           || ((token[strlen(token)-1] == ',') && (token[strlen(token)-2]
== 'e')\
           && (token[strlen(token)-3] == 't') && (token[strlen(token)-4]
== 'a')\
           && (token[strlen(token)-5] == 'd') && (token[strlen(token)-6]
== '_')) ) {
          count_date = display_count-1;
          ++display_count;
          }
     }

     /*
      * GRAB THE LOCATION FIELD COUNT TO EVAL
      */
     if ( strlen(token) != NULL ) {
     if ( (strcmp( (char *) token, "location" ) == 0)\
           || (strcmp( (char *) token, "location," ) == 0) ) {
          location_count = display_count-1;
          }
     }

     /*
      * IF TOKEN IS NOT FROM AND
      */
     if ( (strcmp ( token, "from" ) != 0) && (END == 0) ) {
          ++display_count;
          }

     /*
      * IF FROM END FIELD COUNT SET
      */
     if ( strcmp ( token, "from" ) == 0 ) {
          END=1;
          }

     /*
      * IF TOKEN BEGINS WITH A DASH AND DASH NOT SET
      * SET DASH AND DEINC DISPLAY COUNT BY ONE
      */
     if ( (DASH == 0) && (token[0] == '-') ) {
          DASH=1;
          display_count-=1;
          }

     /*
      * IF TOKEN DOES NOT BEGIN WITH A DASH AND THE
      * DASH IS SET THAN TOKEN IS NEXT AFTER DASH
      * SET START PARSE
      */
     if ( (DASH == 1) && (token[0] != '-') ) {
          START=1;
          }

     /*
      * IF TOKEN IS THE ANSWER CODE AND PARSE HAS BEGAN
      * THE SET COMPLETE
      */
     if ( (strcmp ( token, "ANS8002I" ) == 0) && ( BEGIN == 1 ) ) {
          COMPLETE=1;
          }

     /*
      * BEGIN IF NOT COMPLETE BUT START IS SET THEN DO THIS
      */
     if ( (COMPLETE != 1) && (START == 1) ) {

          /*
           * BEGIN IF THE RETURN COUNT AND DISPLAY COUNT ARE EQ
           */
          if ( return_count == display_count ) {
               /*
                * PRINT A EOL TO STDOUT
                */
               printf ("\n");
               /*
                * SET THE RETURN COUNT TO ZERO
                */
               return_count=0;
          /*
           * END IF THE RETURN COUNT AND DISPLAY COUNT ARE EQ
           */
          }


          /*
           * BEGIN IF TOKEN NE NULL
           */
          if ( token != NULL ) {

               /*
                * LETS NOT PRINT ALL THIS NANOSECOND GARBAGE
                * IF THIS IS A TIME
                * SEE REVISION NOTE ABOUT WHAT ADSM IS DOING HERE. :(
                */
               if ( (token[2] == ':') && (token[5] == ':') ) {
                    printf ( " %c%c:%c%c  ", token[0], token[1],\
                    token[3], token[4] );
                    }

               /*
                * IF THE CURRENT COUNT IS A _date FIELD
                */
               if ( return_count == count_date ) {

                    /*
                     * IF THIS TOKEN IS THE DATE
                     */
                    if ( (token[4] == '-') && (token[7] == '-') ) {
                         printf ( "%s  ", token );
                         }

                    /*
                     * IF THIS TOKEN IS NOT THE DATE THEN
                     * THE DATE IS MISSING PRINT THIS SINCE
                     * WE REQUIRE THE DATE BE THE LAST ITEM
                     * IN THE SELECT
                     */
                    if ( (token[4] != '-') && (token[7] != '-') ) {
                         printf ( "0000-00-00   00:00\n" );
                         return_count=0;
                         }
                    }

               /*
                * IF THE CURRENT COUNT IS NOT A _date FIELD
                */
               if ( return_count != count_date ) {

                    /*
                     * CHECK IF LOCATION
                     * IF TRUE THEN SEE IF THE VALUE EQ ONE OF THE
                     * ACCEPTED VALUES, IF NOT SHOULD BE A VOID FIELD.
                     * IF THE LOCATION IS A TYPO YOU WILL SEE THE UNKNOWN
                     * RIGHT BEFORE THE TYPO LOCATION AND THEN THE VOLUME
                     * CAN BE UPDATED TO CORRECT THIS.
                     */
                    if ( return_count == location_count ) {
                         if ( (strcmp ( token, "OFFSITE" ) != 0) &&\
                         (strcmp ( token, "ONSITE_IBM7331" ) != 0) &&\
                         (strcmp ( token, "ONSITE_IBM7337" ) != 0) &&\
                         (strcmp ( token, "ONSITE_IBM7337A" ) != 0) &&\
                         (strcmp ( token, "ONSITE_T_IBM7337" ) != 0) &&\
                         (strcmp ( token, "ONSITE_T_IBM7337A" ) != 0) ) {
                              printf ( "UNKNOWN  " );
                              ++return_count;
                              }
                         }
                    /*
                     * IF THIS IS NOT A TIME STAMP
                     */
                    if ( (token[2] != ':') && (token[5] != ':') ) {
                         printf ( "%s  ", token );
                         }
                    }

               /*
                * INCREMENT THE COUNT
                */
               return_count++;

          /*
           * END IF TOKEN NE NULL
           */
          }

     /*
      * END IF NOT COMPLETE BUT START IS SET THEN DO THIS
      */
     }

/*
 * END IF BEGIN IS SET
 */
}

/*
 * END DO WHILE TOKEN NE NULL
 */
}while ( token != NULL );

/*
 * PRINT A EOL JUST FOR THE HECK OF IT
 */
printf ("\n" );

/*
 * END MAIN FUNCTION
 */
}

 This script requires a argument of the storage pool name. A mailer script
for each storage ppol calls this script and then mails the output.

***************************************************************************
adsm.mail.stgpool.volumes.sh

#!/bin/ksh
# Korn Shell Script
# adsm.mail.stgpool.volumes.sh: SQL Select volumes by stgpool
# Written By: Bart G. Colbert 09/23/1999
VERSION="1.2"
# Revisions:
# *) 09/28/1999 Bart Colbert V1.1
#    Adding VOLUMES:STATUS field.
#
# *) 09/30/1999 Bart Colbert V1.2
#    adsm.select.parse has been modified to handle the _date field.
#    the REQUIREMENT is that you may only use one _date field in the select
#    statement and that it shall be placed as the last field.
#
# INFORMATION ABOUT FIELD WIDTHS FOR awk.
#
# ACCESS = %12
# CAPACITY = %9
# _DATE (ANY) = %11
# LOCATION = %18
# PCTUTIL = %6
# STATUS = %8
# VOLUME = %7
#
# INIT/EXPORT VARS
#
APP_HOME="/home/radsm/bin"
MACHINE=$(uname -n)
TIMESTAMP=$(date)
#
# SELECT INFO
#
SELECT_INFO=$(dsmadmc -id=XXXX -password=XXXX\
          "select volume_name,\
          est_capacity_mb, pct_utilized, access,\
          status, location, last_write_date\
          from volumes where stgpool_name='$1'\
          order by volume_name")
#
# CREATE THE FORMAT
#
echo "DATE          = $TIMESTAMP"
echo "HOSTNAME      = $MACHINE"
echo "MESSAGE TYPE  = Adsm monitor"
echo "MESSAGE LEVEL = Information"
echo ""
echo " VOLUME CAPACITY PCTUTIL    ACCESS  STATUS          LOCATION LAST
WRITE"
echo "
-----------------------------------------------------------------------"
echo $SELECT_INFO | $APP_HOME/adsm.select.parse | awk '{printf
echo $SELECT_INFO | $APP_HOME/adsm.select.parse | awk '{printf
"%7s%9s%6s%12s%8s%18s%11s\n",$1,$2,$3,$4,$5,$6,$7}'

 This script calls the adsm.mail.stgpool.sh and provides the storage pool
name. All of the output is piped to the mail program.

***************************************************************************
adsm.mail.STORAGE_POOL_NAME.volumes.sh

#!/bin/ksh
# Korn Shell Script
# adsm.mail.STORAGE_POOL_NAME.volumes.sh: This script calls
# adsm.mail.stgpool.volumes.sh and mails then info
# Written By: Bart G. Colbert 09/23/1999
#
VERSION="1.0"
#
# INIT AND EXPORT VARS
#
APP_HOME="/home/radsm/bin"
#
# CALL STORAGE POOL SCRIPT AND MAIL INFO
#
$APP_HOME/adsm.mail.stgpool.volumes.sh STORAGE_POOL_NAME | mail -s
"BACKUP_DLT_POOL Volumes" user AT server DOT dom, user AT server DOT dom

#!/bin/ksh
# Korn Shell Script
# adsm.mail.ACCESS.volumes.sh: SQL Select volumes by access
# Written By: Bart G. Colbert 09/27/1999
VERSION="1.0"
# Revisions:
#
# INFORMATION ABOUT FIELD WIDTHS FOR awk.
#
# ACCESS = %12
# CAPACITY = %9
# _DATE (ANY) = %11
# LOCATION = %18
# PCTUTIL = %6
# STATUS = %8
# STGPOOL = %19
# VOLUME = %7
#
# INIT/EXPORT VARS
#
APP_HOME="/home/radsm/bin"
MACHINE=$(uname -n)
TIMESTAMP=$(date)
#
# SELECT INFO
#
SELECT_INFO=$(dsmadmc -id=XXXX -password=XXXX\
      "select volume_name, stgpool_name, location,\
      last_write_date from volumes where access='$1'\
      order by stgpool_name, volume_name")
#
# CREATE THE FORMAT
#
echo "DATE          = $TIMESTAMP"
echo "HOSTNAME      = $MACHINE"
echo "MESSAGE TYPE  = Adsm monitor"
echo "MESSAGE LEVEL = Information"
echo ""
echo " SELECT VOLUMES BY ACCESS EQUALS $1"
echo ""
echo "VOLUME             STGPOOL          LOCATION       LAST WRITE"
echo "-------------------------------------------------------------"
echo $SELECT_INFO | $APP_HOME/adsm.select.parse  | awk '{printf
"%7s%19s%18s%11s%6s\n",$1,$2,$3,$4,$5}'
<Prev in Thread] Current Thread [Next in Thread>
  • Formatting select output AIX 3.1.2.40 3.1.2.6 Client, Bart Colbert <=