Author |
Message
|
Boomn4x4 |
Posted: Thu Feb 16, 2012 6:31 am Post subject: Scripting MQSC commands |
|
|
Disciple
Joined: 28 Nov 2011 Posts: 172
|
Is there a simple way to execute MQSC commands from a script?
For example, I'd like to return the results of "DISPLAY QSTATUS(DLQ) MONITOR", but I don't want to have to go through "runmqsc" to do it.
I'm trying to write a perl script to pull the monitoring information from these status commands. |
|
Back to top |
|
 |
bruce2359 |
Posted: Thu Feb 16, 2012 6:44 am Post subject: |
|
|
 Poobah
Joined: 05 Jan 2008 Posts: 9469 Location: US: west coast, almost. Otherwise, enroute.
|
Yes. Do a bit of research on how to execute the runmqsc script command processing application. Then craft the script in PERL or whatever other scripting language you choose. _________________ I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live. |
|
Back to top |
|
 |
JasonE |
Posted: Thu Feb 16, 2012 6:45 am Post subject: |
|
|
Grand Master
Joined: 03 Nov 2003 Posts: 1220 Location: Hursley
|
A simple way to execute commands from within a script is something like
echo DISPLAY QSTATUS(DLQ) MONITOR | runmqsc QM |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Feb 16, 2012 7:46 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
If you want to execute MQSC commands without actually calling out to runmqsc, then you don't actually want to execute MQSC commands.
You want to send PCF messages, which are the programming API equivalent to MQSC.
The perl modules should provide at least some support for these. happy search.cpan.org! |
|
Back to top |
|
 |
Boomn4x4 |
Posted: Thu Feb 16, 2012 8:25 am Post subject: |
|
|
Disciple
Joined: 28 Nov 2011 Posts: 172
|
Instead of writing a long C program, I put the commands I wanted to send in a .in file, then redirected the file stdin to runmqsc. The system call from my Perl script is:
runmqsc < mycommands.in
... I doubt its the "right" way to do this, but it works. |
|
Back to top |
|
 |
bruce2359 |
Posted: Thu Feb 16, 2012 8:47 am Post subject: |
|
|
 Poobah
Joined: 05 Jan 2008 Posts: 9469 Location: US: west coast, almost. Otherwise, enroute.
|
Boomn4x4 wrote: |
... I doubt its the "right" way to do this, but it works. |
It is the way IBM suggests that you process MQSC scripts. _________________ I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live. |
|
Back to top |
|
 |
Vitor |
Posted: Thu Feb 16, 2012 8:48 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Boomn4x4 wrote: |
Instead of writing a long C program |
I think my most worthy associate anticipated you would write a short Perl program that issued PCF commands via the modules provided.
Boomn4x4 wrote: |
... I doubt its the "right" way to do this, but it works. |
I wouldn't describe it as wrong. Cumbersome is the adjective that springs to mind.
How do you trap failures, e.g. displaying a queue that doesn't exist? Or creating an object that already exists? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
zpat |
Posted: Thu Feb 16, 2012 8:55 am Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
Support pac MO71 can run MQSC scripts or commands remotely - from a GUI.
The same author also wrote a remote runmqsc line comand - I can't remember the support pac name for that. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Feb 16, 2012 9:43 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Vitor wrote: |
Boomn4x4 wrote: |
Instead of writing a long C program |
I think my most worthy associate anticipated you would write a short Perl program that issued PCF commands via the modules provided. |
Yes. |
|
Back to top |
|
 |
PeterPotkay |
Posted: Thu Feb 16, 2012 4:52 pm Post subject: |
|
|
 Poobah
Joined: 15 May 2001 Posts: 7722
|
zpat wrote: |
Support pac MO71 can run MQSC scripts or commands remotely - from a GUI.
The same author also wrote a remote runmqsc line comand - I can't remember the support pac name for that. |
MO72 _________________ Peter Potkay
Keep Calm and MQ On |
|
Back to top |
|
 |
LouML |
Posted: Wed Dec 12, 2012 4:48 am Post subject: Changing runmqsc to mo72's mqsc in perl script |
|
|
 Partisan
Joined: 10 Nov 2005 Posts: 305 Location: Jersey City, NJ / Bethpage, NY
|
MQ 7.5 on Solaris Sparc.
I've been using dgolding's code below to successfully send commands to runmqsc.
I now want to use this for remote queue managers. I replaced the call to runmqsc with a call to mo72's mqsc but it does not work. I do not even get any output in CHS_OUT.
Code: |
open (CHS_OUT, "echo 'dis qs(*) all where (chltype eq svrconn)'|runmqsc $qm|"); |
Code: |
open (CHS_OUT, "mqsc -m $qm -l -c $svrconn -h '$server($port)' -p format=no -C 'dis chs(*) all where (chltype eq svrconn)'"); |
The same command executed from a command line works fine. I even tried to change the command to just a simple '-?' for the help display.
Code: |
open (CHS_OUT, "mqsc -?"); |
dgolding's code
Code: |
#! /usr/bin/perl -w
#
# Show the current depth of all queues for a given queue manager
#
#
# Who When What
# dgolding 09.06.04 Initial coding.
# dgolding 07.01.10 Fixed uninitialized variable bug.
#
$qm = $ARGV[0];
$host = $ARGV[1];
$port = $ARGV[2];
$svrconn = $ARGV[3];
print $qm,"\n";
print $host,"\n";
print $port,"\n";
print $svrconn ,"\n";
open (CHS_OUT, "echo 'dis ql(*) all'|runmqsc $qm|");
while (<CHS_OUT>)
{
# $ctr++;
# print ("DEBUG: $ctr IV=\"$_\"\n");
if ( /QUEUE\(/ )
{
$QueueName = ValueParser("QUEUE", 6);
}
if ( /IPPROCS\(/ )
{
$InpProcs = ValueParser("IPPROCS", 8);
}
if ( /CURDEPTH\(/ )
{
$CurDepth = ValueParser("CURDEPTH", 9);
}
if ( /OPPROCS\(/ )
{
$OutProcs = ValueParser("OPPROCS", 8);
write;
}
}
format STDOUT =
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>> @>>>> @>>>>>>
$QueueName, $InpProcs, $OutProcs, $CurDepth
.
#
# Value parser subroutine
#
sub ValueParser
{
my($ValueName,$ValueLength) = @_;
$ValueStart = index($_, "$ValueName\(") + $ValueLength;
$ValueStop = index($_, "\)");
if ( $ValueStop < $ValueStart )
{
$ValueStop = rindex($_, "\)");
}
$ValueLength = $ValueStop - $ValueStart;
return substr($_, $ValueStart, $ValueLength);
} |
_________________ Yeah, well, you know, that's just, like, your opinion, man. - The Dude |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Dec 12, 2012 4:52 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You'll want to use a PCF Escape message, instead.
something vaguely like
Code: |
PCFMessage command;
PCFParameter escapeTextParameter;
command = new PCFMessage(CMQCFC.MQCMD_ESCAPE);
command.addParameter(escapeTypeParameter);
escapeTextParameter = new MQCFST(CMQCFC.MQCACF_ESCAPE_TEXT,
"delete qlocal(SYSTEM.ADMIN.COMMAND.QUEUE)");
command.addParameter(escapeTextParameter);
// send pcf messages
try {
responses = dmQueueManager.sendCommand(t, command);
} catch (MQException e1) {
|
Unless you know you're talking to a zOS qmgr, in which case you could send just the raw MQSC command in an MQFMT_STRING message.
EDIT: of course, that's Java code, not Perl code. but it should be mostly the same either way. |
|
Back to top |
|
 |
LouML |
Posted: Wed Dec 12, 2012 7:32 am Post subject: |
|
|
 Partisan
Joined: 10 Nov 2005 Posts: 305 Location: Jersey City, NJ / Bethpage, NY
|
I got it to work. I wound up using the following and doing a foreach through :
Code: |
@result=`mqsc -m $qm -l -c $svrconn -h '$server($port)' -p format=no -C 'dis chs(*) all where (chltype eq svrconn)'`;
|
instead of
Code: |
open (CHS_OUT, "mqsc -m $qm -l -c $svrconn -h '$server($port)' -p format=no -C 'dis chs(*) all where (chltype eq svrconn)'"); |
_________________ Yeah, well, you know, that's just, like, your opinion, man. - The Dude |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Dec 12, 2012 8:59 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
|
Back to top |
|
 |
|