OK, y'all convinced me that always using a 1M buffer for vmcp is not the
best idea. I appreciate all the feedback.

Here's my first take at a bash function to retry a vmcp command with a few
boundary test cases:

# cat testvmcp
#!/bin/bash

function zVerbose
 {
  echo "$@"
 }

#+--------------------------------------------------------------------------+
function zCPcmd
# invoke a CP command with the vmcp module/command
# Args 1-n: the command to issue
# Return:   the CP return code (not the vmcp rc)
#+--------------------------------------------------------------------------+
 {
  : SOURCE: ${BASH_SOURCE}
  : STACK:  ${FUNCNAME[@]}

  local CPrc=0                             # assume CP command succeeds
  local CPout                              # CP output

  zVerbose "Invoking: $vmcpCmd $@"
  CPout=`$vmcpCmd $@ 2>&1`                 # run the CP command
  local rc=$?
  if [ "$rc" = 2 ]; then                   # output buffer overflow
    local bytes=`echo $CPout | awk -F'(' '{print $2}' | awk '{print $1}'`
    if [[ "$bytes" -gt 1048576 ]]; then    # output too large
      zVerbose "Error: output of $bytes bytes larger than 1 MB"
      return 2
    fi
    zVerbose "Warning: increasing vmcp buffer size to $bytes bytes and
trying again"
    CPout=`$vmcpCmd --buffer=$bytes $@ 2>&1`
    local rc2=$?
    if [ $rc2 != 0 ]; then                 # capture the CP return code
after "#"
      CPrc=`echo $CPout | grep "Error: non-zero CP" | awk -F# '{print $2}'`
    fi
  elif [ $rc != 0 ]; then                  # capture the CP return code
after "#"
    CPrc=`echo $CPout | grep "Error: non-zero CP" | awk -F# '{print $2}'`
  fi
  zVerbose "CP output:"                    # show the output in verbose mode
  zVerbose "$CPout"                        # show the output in verbose mode
  zVerbose "CP return code: $CPrc"         # show the CP return code in
verbose mode
  return $CPrc                             # return code from CP
 }                                         # zCPcmd()

# main
vmcpCmd="/sbin/vmcp"

zCPcmd "Q DASD DETAILS 0000-07FF"
echo
zCPcmd "Q DASD DETAILS 0000-FFFF"
echo
zCPcmd "NOT A CP COMMNAD"


Here's a test of running it:

# testvmcp
Invoking: /sbin/vmcp Q DASD DETAILS 0000-07FF
Warning: increasing vmcp buffer size to 109568 bytes and trying again
CP output:
HCPQDD040E Device 0000 does not exist
HCPQDD040E Device 0001 does not exist
...
HCPQDD040E Device 07FF does not exist
Error: non-zero CP response for command 'Q DASD DETAILS 0000-07FF': #40
CP return code: 40

Invoking: /sbin/vmcp Q DASD DETAILS 0000-FFFF
Error: output of 2577330 bytes larger than 1 MB

Invoking: /sbin/vmcp NOT A CP COMMNAD
CP output:
Error: non-zero CP response for command 'NOT A CP COMMNAD': #1
CP return code: 1

    -Mike M

----------------------------------------------------------------------
For LINUX-390 subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390
----------------------------------------------------------------------
For more information on Linux on System z, visit
http://wiki.linuxvm.org/

Reply via email to