ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » General Discussion » Shell scripting question while setmqauting

Post new topic  Reply to topic
 Shell scripting question while setmqauting « View previous topic :: View next topic » 
Author Message
PeterPotkay
PostPosted: Thu Nov 20, 2008 2:42 pm    Post subject: Shell scripting question while setmqauting Reply with quote

Poobah

Joined: 15 May 2001
Posts: 7722

Line #1 below writes a copy of the setmqaut command I intend to execute to the logfile.
Line #2 below executes the setmqaut command, and writes the results of the command to the logfile.

Code:
echo "setmqaut -m $QMGRNAME -t qmgr -g mqappsg2 -all +connect +inq " >> $LOGFILE
setmqaut -m $QMGRNAME -t qmgr -g mqappsg2 -all +connect +inq >> $LOGFILE 2>&1



Does anyone have an idea how to combine the 2 lines so that both a copy of the command and its results go to the log file? I don't want to have to type "setmqaut -m $QMGRNAME -t qmgr -g mqappsg2 -all +connect +inq" twice. I have dozens and dozens of setmqaut commands to run, so its lame having to type everything twice, and its open to typos, where the command on line 1 does not match the command executed on line 2. Yes, I have heard of copy and paste. But the script would be easier on the eyes if it was half as big and copy and paste still takes time.


I've considered making a function, where I pass in the object type, the object name, the group name and all the authorizations required. The function would first print the command to the log file, and then execute it on the next line. But I wonder if there is an easier way, as this will be complicated for the next person that has to look at it.
_________________
Peter Potkay
Keep Calm and MQ On
Back to top
View user's profile Send private message
gbaddeley
PostPosted: Thu Nov 20, 2008 4:36 pm    Post subject: Reply with quote

Jedi Knight

Joined: 25 Mar 2003
Posts: 2538
Location: Melbourne, Australia

eg. in ksh script

MySetMqAut() {
echo "setmqaut $1" >>$LOGFILE
setmqaut $1 >>$LOGFILE 2>&1
}

MySetMqAut "-m $QMGRNAME -t qmgr -g mqappsg2 -all +connect +inq"
MySetMqAut "-m $QMGRNAME ....."

The arg to MySetMqAut can be recs read from a file etc.

HTH
_________________
Glenn
Back to top
View user's profile Send private message
jhidalgo
PostPosted: Fri Nov 21, 2008 2:06 pm    Post subject: Reply with quote

Disciple

Joined: 26 Mar 2008
Posts: 161

Since this is a question about shell scripting we need to know what shell are you using, ksh really sucks, if you can use another option, (ba)sh for example and use set -v, script, or something like that.
Back to top
View user's profile Send private message
Michael Dag
PostPosted: Fri Nov 21, 2008 3:09 pm    Post subject: Reply with quote

Jedi Knight

Joined: 13 Jun 2002
Posts: 2607
Location: The Netherlands (Amsterdam)

Or get away from scripting at all... there are wheels out there
_________________
Michael



MQSystems Facebook page
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
gbaddeley
PostPosted: Sun Nov 23, 2008 5:03 pm    Post subject: Reply with quote

Jedi Knight

Joined: 25 Mar 2003
Posts: 2538
Location: Melbourne, Australia

jhidalgo wrote:
Since this is a question about shell scripting we need to know what shell are you using, ksh really sucks, if you can use another option, (ba)sh for example and use set -v, script, or something like that.


Yes, every Unix shell script language is different, so the shell name needs to be stated.

We all have our personal favourite and tend to use that most of the time. For me, its ksh (the Korn Shell). I like it and over the last 8 years have learnt many programming tips for using it effectively to do weird and wonderful things.
_________________
Glenn
Back to top
View user's profile Send private message
dgolding
PostPosted: Mon Nov 24, 2008 2:49 am    Post subject: Reply with quote

Yatiri

Joined: 16 May 2001
Posts: 668
Location: Switzerland

jhidalgo wrote:
Quote:
ksh really sucks, if you can use another option, (ba)sh for example and use set -v, script, or something like that.


And then one day you find yourself working on a site that does not allow ANY freeware on their machines (because of lack of legal liability on these tools, for example) - and you're stuck. This is the same reason that I learned "vi", and not "emacs", technically superior maybe but if you can't use it you can find yourself helpless as you struggle to use an unfamiliar editor.
Back to top
View user's profile Send private message Visit poster's website
gs
PostPosted: Mon Nov 24, 2008 5:44 am    Post subject: Reply with quote

Master

Joined: 31 May 2007
Posts: 254
Location: Sweden

If you want to keep it on one line (without using functions), you could use:
Code:
sh -v yourscript.sh 1>>logfile 2>>logfile

yourscript.sh simply contains the command(s) you want to execute and logfile will contain both command & output.
Back to top
View user's profile Send private message
PeterPotkay
PostPosted: Mon Nov 24, 2008 8:48 am    Post subject: Reply with quote

Poobah

Joined: 15 May 2001
Posts: 7722

Glenn,
Your example worked great. I have it all done except for one part. I'm trying to set +inq for all queues for a group, but the function just won't take anything I give it successfully.

If I manually type this from the command line it works:
Code:
setmqaut -m HIGWMBD1 -n "*.**"  -t queue -g mqappsg2 -all +set +inq
The setmqaut command completed successfully.


Here are all the various ways I tried it, and the results. The last 3 look like they should work based on the display of the command about to be executed, but no luck. Any ideas?

Code:

export QMGRNAME=$1
export ALLQUEUES=*.**
export ALLQUEUES2='*.**'
export LOGFILE=/var/mqm/scriptlog/setmqautOutput.$QMGRNAME.`date "+%y%m%d-%H%M"`.log

MySetMqAut()
{
echo "setmqaut $1" >> $LOGFILE
setmqaut $1 >> $LOGFILE 2>&1
echo "-------" >> $LOGFILE
}

MySetMqAut "-m $QMGRNAME -n *.** -t queue -g mqappsg2 -all +inq"
MySetMqAut "-m $QMGRNAME -n \*.**\ -t queue -g mqappsg2 -all +inq"
MySetMqAut "-m $QMGRNAME -n \'*.**\' -t queue -g mqappsg2 -all +inq"
MySetMqAut "-m $QMGRNAME -n "\""*.**\ -t queue -g mqappsg2 -all +inq"
MySetMqAut "-m $QMGRNAME -n \*.** -t queue -g mqappsg2 -all +inq"
MySetMqAut "-m $QMGRNAME -n \*.\** -t queue -g mqappsg2 -all +inq"
MySetMqAut "-m $QMGRNAME -n $ALLQUEUES -t queue -g mqappsg2 -all +inq"
MySetMqAut "-m $QMGRNAME -n $ALLQUEUES2 -t queue -g mqappsg2 -all +inq"
MySetMqAut "-m $QMGRNAME -n '*.**' -t queue -g mqappsg2 -all +inq"
MySetMqAut "-m $QMGRNAME -n \"*.**\" -t queue -g mqappsg2 -all +inq"
MySetMqAut "-m $QMGRNAME -n "\""*.**\" -t queue -g mqappsg2 -all +inq"



Code:

setmqaut -m HIGWMBD1 -n *.** -t queue -g mqappsg2 -all +inq
AMQ7093: An object type is required but you did not specify one.
Usage: setmqaut [-m QMgrName] [-n ObjName] -t ObjType (-p Principal | -g Group)
  [-s ServiceComponent] Authorizations
-------
setmqaut -m HIGWMBD1 -n \*.**\ -t queue -g mqappsg2 -all +inq
AMQ7226: The profile name is invalid.
-------
setmqaut -m HIGWMBD1 -n \'*.**\' -t queue -g mqappsg2 -all +inq
AMQ7226: The profile name is invalid.
-------
setmqaut -m HIGWMBD1 -n "*.**\ -t queue -g mqappsg2 -all +inq
AMQ7226: The profile name is invalid.
-------
setmqaut -m HIGWMBD1 -n \*.** -t queue -g mqappsg2 -all +inq
AMQ7226: The profile name is invalid.
-------
setmqaut -m HIGWMBD1 -n \*.\** -t queue -g mqappsg2 -all +inq
AMQ7226: The profile name is invalid.
-------
setmqaut -m HIGWMBD1 -n *.** -t queue -g mqappsg2 -all +inq
AMQ7093: An object type is required but you did not specify one.
Usage: setmqaut [-m QMgrName] [-n ObjName] -t ObjType (-p Principal | -g Group)
  [-s ServiceComponent] Authorizations
-------
setmqaut -m HIGWMBD1 -n *.** -t queue -g mqappsg2 -all +inq
AMQ7093: An object type is required but you did not specify one.
Usage: setmqaut [-m QMgrName] [-n ObjName] -t ObjType (-p Principal | -g Group)
  [-s ServiceComponent] Authorizations
-------
setmqaut -m HIGWMBD1 -n '*.**' -t queue -g mqappsg2 -all +inq
AMQ7226: The profile name is invalid.
-------
setmqaut -m HIGWMBD1 -n "*.**" -t queue -g mqappsg2 -all +inq
AMQ7226: The profile name is invalid.
-------
setmqaut -m HIGWMBD1 -n "*.**" -t queue -g mqappsg2 -all +inq
AMQ7226: The profile name is invalid.

_________________
Peter Potkay
Keep Calm and MQ On
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Mon Nov 24, 2008 4:10 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

Peter have you tryied this for all queues?

MySetMqAut "-m $QMGRNAME -n \*.\*\* -t queue -g mqappsg2 -all +inq"


_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
gbaddeley
PostPosted: Mon Nov 24, 2008 4:50 pm    Post subject: Reply with quote

Jedi Knight

Joined: 25 Mar 2003
Posts: 2538
Location: Melbourne, Australia

Fun and games with double quotes, single quotes and command execution !!

When the shell executes setmqaut -m HIGWMBD1 -n *.** -t queue -g mqappsg2 -all +inq it expands the * as a regular expression for the matching names of files in the current directory, so setmqaut fails.

Entering the command setmqaut -m MQGNB01 -n \*.\*\* -t queue -g sabayon -all +inq prevents this from happening. setmqaut -m MQGNB01 -n '*.**' -t queue -g sabayon -all +inq and setmqaut -m MQGNB01 -n "*.**" -t queue -g sabayon -all +inq also work. The trick is to pass one of these as a function argument and execute the command in a script.

The following little test script worked for me on Redhat Linux:
#!/usr/bin/ksh

MySetMqAut()
{
echo setmqaut $1 >>$LOGFILE
ksh -c "setmqaut $1" >>$LOGFILE 2>&1
}

QMGRNAME=MQGNB01
LOGFILE=$0.log

MySetMqAut "-m $QMGRNAME -n '*.**' -t queue -g sabayon -all +inq"

echo "Contents of $LOGFILE :"
cat $LOGFILE


I tried various things like ` ` and ( ) and playing with back slashes, single and double quotes in various places, but needed to resort to the 'ksh -c' method.
_________________
Glenn
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Mon Nov 24, 2008 8:05 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

Just refresh my memory...
Doesn't the -c reexecute the .profile?

The question then comes as to what profile type you are executing this in...
The output of the env command could probably tell us more about the differences...

Thanks
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
PeterPotkay
PostPosted: Mon Nov 24, 2008 8:16 pm    Post subject: Reply with quote

Poobah

Joined: 15 May 2001
Posts: 7722

\*.\*\* didn't do it.

But adding a ksh -c inside the function did allow me to pass '*.**' into the function successfully. -c means "Causes the Korn shell to read commands from the String variable"

It worked without coding the #!/usr/bin/ksh at the head of the file, but I added that line anyway, I assume for portability?
_________________
Peter Potkay
Keep Calm and MQ On
Back to top
View user's profile Send private message
gs
PostPosted: Mon Nov 24, 2008 11:52 pm    Post subject: Reply with quote

Master

Joined: 31 May 2007
Posts: 254
Location: Sweden

PeterPotkay wrote:

It worked without coding the #!/usr/bin/ksh at the head of the file, but I added that line anyway, I assume for portability?


Not specifying the line means the commands in your file will be executed in the current shell, or you can run them through the command specified on that line, be it a ksh, bash, perl or some other command interpreter.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » General Discussion » Shell scripting question while setmqauting
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.