954,525 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to loop inside application via script

Here's what I'm trying to do... I want to connect to a command line application and send it instructions from inside a script. I need to do a loop as there are multiple things I want to do. I was able to accomplish this by connecting and disconnecting inside the loop, but I'd rather connect once, do my loop and then disconnect once. Is that possible? Here is my current script. (Note I'm connecting to a queue manager and executing something for each queue defined in a text file).

#!/usr/bin/ksh
if [ $# -lt 2 ]
then
		echo "USAGE: $0 qm queue_file"
		exit 1
fi

qm=$1
file=$2
if [ ! -r $file ]
then
		echo "${file} does not exist...."
		exit 1
fi
cat ${file} | while read queueName
do
		runmqsc ${qm}<<!
		display ql(${queueName}) CURDEPTH
		end
!
done


(So basically, the 'runmqsc' should only be executed once and the 'end' should only be executed once...)

winbatch
Posting Pro in Training
466 posts since Feb 2005
Reputation Points: 68
Solved Threads: 18
 

I came up with a workaround (which is to have it create a different script and then run that script). Let me know if there is a better way:

#!/usr/bin/ksh

if [ $# -lt 2 ]
then
echo "USAGE: $0 qm queue_file"
exit 1
fi


qm=$1
file=$2

if [ ! -r $file ]
then
echo "${file} does not exist...."
exit 1
fi

if [ ! -r run.sh ]
then
\rm run.sh
fi
echo "runmqsc ${qm}< run.sh
cat ${file} | while read queueName
do
echo "display ql(${queueName}) CURDEPTH">> run.sh
done
echo "end" >> run.sh
echo "!" >> run.sh
chmod 777 run.sh
run.sh

winbatch
Posting Pro in Training
466 posts since Feb 2005
Reputation Points: 68
Solved Threads: 18
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You