需求
有IBM MQ服务器,在做异地灾备切换时,为保证消息不丢失,需要在切换前检查QM中是否有消息。由于单台服务器上QM比较多,里面的QUEUE更多,若需要肉眼登录查看,甚是低效。因而有此需求。
解决方案
#!/bin/bash
#param1: mq_name
#param2: qlocal
GetQueueDepth()
{
if [ $# != 2 ]
then
echo "Usage : FUNCTION QMNAME QLOCAL"
return 1
fi
QMNAME="$1"
QLOCAL="$2"
AAA=`runmqsc $QMNAME <<!
display qlocal($QLOCAL)
end
!`
echo ${AAA#*CURDEPTH} | awk '{print $1}' | cut -d '(' -f2|cut -d ')' -f1
}
GetAllQM()
{
AAA=`dspmq`
for item in $AAA
do
PREFIX=${item:0:6}
if [ "$PREFIX" = "QMNAME" ]
then
echo ${item#*QMNAME} | cut -d '(' -f2|cut -d ')' -f1
fi
done
}
GetAllQueue()
{
if [ $# != 1 ]
then
echo "Usage : FUNCTION QMNAME"
return 1
fi
QMNAME="$1"
AAA=`runmqsc $QMNAME <<!
display qlocal(*)
end
!`
for item in $AAA
do
PREFIX=${item:0:5}
if [ "$PREFIX" = "QUEUE" ]
then
QUEUENAME=`echo ${item#*QUEUE} | cut -d '(' -f2|cut -d ')' -f1`
QUEUE_PREFIX=${QUEUENAME:0:6}
if [ "$QUEUE_PREFIX" != "SYS