1

I'm trying to write automation routines for IBM MQ (on an IBM i to make life that little more difficult) and struggling with processing the rather over-formatted output.

It seems to insist on two fixed-width columns for all output and as these columns aren't wide enough for some values (notably SYSTEM.* queue names) the output per entry can be on different numbers of lines.

I'd like to avoid writing a parser just to fetch basic values from MQ. Can I force the output to a single (long) line, or specify column widths? I've got enough Unix-fu to combine pairs of lines and even strip out text with the likes of grep, sed, paste, but when the number of lines changes I'm tearing my hair out.

JoshMc
  • 10,239
  • 2
  • 19
  • 38
zkarj
  • 657
  • 9
  • 23
  • If you want it unformatted then just use the single long line. Or better yet, write code and use PCF commands. – Roger Jul 19 '17 at 04:08
  • That's my question - can I force it to output each entry on a single long line? I see no obvious options for that. It always has two entries max per line. – zkarj Jul 19 '17 at 04:37
  • What version of IBM MQ? – JoshMc Jul 19 '17 at 05:33
  • The version is 7.1.0.6. 7.1.x being the latest we can go to currently. – zkarj Jul 19 '17 at 20:17
  • For just configuration information (not running values like CURDEPTH, IPPROCS, etc) IBM MQ v7.1 and later comes with the dmpmqcfg program on Unix/Windows and [DMPMQMCFG](https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_7.1.0/com.ibm.mq.doc/ia_DMPMQMCFG.htm) on IBM i. This can be called with `OUTPUT(*ONELINE)` to output each object on a single line. – JoshMc Jul 20 '17 at 17:23
  • 1
    Also note that in my answer to this question "[UNIX(AIX) script to process a file using only awk or other file processing utilities](https://stackoverflow.com/questions/41800496/unixaix-script-to-process-a-file-using-only-awk-or-other-file-processing-utili/41929096#41929096)" I provide a command that uses a combination of `sed` and `awk` on AIX to parse `runmqsc` output. Given that QSH seems to be someone based off of (if not ported from) AIX, this may work for you also. Just change the output separator to a comma if you want CSV, ex: `OFS=","`. – JoshMc Jul 20 '17 at 17:27

2 Answers2

2

Well, I managed to tame sed and grep enough to get a working solution that can handle the two-or-three line output. It's very specific to this situation but the concepts could be applied to similar scenarios.

In short, I did not find a way to influence the output format of the display command, but did find a way to process it.

The following QShell command (run it with STRQSH) gives me a CSV of queue, current depth, maximum depth. I then use CPYFRMIMPF to move this into a DB2 file for processing.

CHGVAR     VAR(&QSH) VALUE('+
echo "dis qlocal(*) curdepth maxdepth"
  | /QSYS.LIB/QMQM.LIB/RUNMQSC.PGM ''' |< &QMGR |< ''' +
  | grep ''[A-Z]\{4,8\}('' +
  | sed -e ''/QUEUE([-A-Za-z0-9._\/]*)$/{N;s/\n//;}'' +
        -e ''/TYPE([-A-Za-z0-9._\/]*)$/{N;s/\n//;}'' +
        -e ''/CURDEPTH([0-9]*)$/{N;s/\n//;}'' +
        -e ''s/^\ \ *//'' +
        -e ''s/\ \ */,/g'' +
        -e ''s/QUEUE[(]\([-A-Za-z0-9._\/]*\)[)]/"\1"/'' +
        -e ''s/TYPE[(][-A-Za-z0-9._\/]*[)],//'' +
        -e ''s/CURDEPTH[(]\([0-9]*\)[)]/\1/'' +
        -e ''s/MAXDEPTH[(]\([0-9]*\)[)]/\1/'' +
  | grep -v ''SYSTEM.'' +
  > /tmp/mqqueuests.csv+
')

It allows for queue names with alphanumeric and . - _ / characters.

The fundamental solution to the problem of the variable numbers of lines lies in finding lines that do not end with MAXDEPTH( ) and removing the subsequent linefeed by means of the N command in sed. This pulls the next line of the file into the pattern buffer, where the linefeed can be stripped.

zkarj
  • 657
  • 9
  • 23
2

Just ran into the same problem - wanted to have runmqsc output one line per object, without extra messages. I did it this way - on AIX:

echo "DISPLAY CHSTATUS(*) STATUS CHSTATI CHSTADA CURRENT LOCLADDR " | runmqsc MY_MQ_SERVER | sed 's/^[^  ].*$/%/g' | tr -s " " | tr -d "\n" | tr "%" "\n"

So, first of all I created a "separator" out of the unnecessary lines, beginning on the first column (first sed command). Then all series of spaces are shrunk to one space and all newline characteris deleted. Then using the last tr command, the "separators" are converted to newlines, thus creating exactly one line output per object.

--Trifo

Trifo
  • 21
  • 1