Friday 4 March 2016

Clearing all messages from a queue through Shell Script

I have written a shell script to find out how many messages are struck in queue and purging/deleting messages from queue.

 Download the following script and store it in a location such as /usr/local/bin.
 Provide the file permissions and ownership for this script as you see fit. In this example, they are:

$ chmod 755 /usr/local/bin/clear-mq-messages.sh
$ chown mqm:mqm /usr/local/bin/clear-mq-messages.sh
$ ls -l /usr/local/bin/clear-mq-messages.sh
-rwxr-xr-x   1 mqm      mqm            1296 Oct 30 14:34 clear-mq-messages.sh

#!/usr/bin/ksh
echo -e "\nPlease enter the \"queuemanager\" !!!"
                read queuemanager
echo -e "\nPlease enter the \"input_queue\" !!!"
        read inputqueue

struck_message=`echo  "DISPLAY QL($inputqueue) CURDEPTH" | runmqsc $queuemanager | grep 'CURDEPTH(' | sed 's/.*CURDEPTH//' | tr -d '()'`

if [ $struck_message = "0" ]; then
   
echo -e "==============================================="
echo "now no messages in " $inputqueue
echo -e "==============================================="
echo -e "\n\nThank you!!! Bye!!!\n"
exit 0
else
echo -e "==============================================="
    echo "the" $inputqueue "CURDEPTH count is" $struck_message
echo -e "==============================================="

fi
echo -e "Would you really like to flush the $inputqueue? <y/N> "
read prompt
if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]
then
echo -e "************************************************"
echo "clear qlocal($inputqueue)" | runmqsc $queuemanager
 echo -e "************************************************"
               
struck_message2=`echo  "DISPLAY QL($inputqueue) CURDEPTH" | runmqsc $queuemanager | grep 'CURDEPTH(' | sed 's/.*CURDEPTH//' | tr -d '()'`

echo "Now the CURDEPTH count is" $struck_message2
echo -e "************************************************"
else
echo -e "\n\nThank you!!! Bye!!!\n\n"
                  exit 0
fi

Let see how this script will work

while script executing time this script will ask QueueManager name & queue name. 




 Let see CURDEPTH  count only....


If CURDEPTH count is zero, the script will work as below



I hope this information is helpful to you

No comments: