Basically this is my code:
bay=$(prog -some flags)
while [ $bay = "Another instance of this program is running, please exit it first" ]
do
echo "Awaiting Access to program"
do
.....
I have program which will only allow one instance to be run at one time due to the way it interacts with my hardware, when another instance is running it kicks out the following message “Another instance of this program is running, please exit it first”.
I need to beable to run multiple scripts which will utilise this same program so I’ve decided to use the above code. My problem is that when I run my two scripts one will gain access to the program and run as desired but the other will notice the error and then get stuck in an infinate loop echoing “Awaiting Access to program”.
Have missed some thing? Is the Statement executing the CLI command or just reffering back to its origanal execution? Or is my problem else where?
You are not updating your
bayvariable inside of the loop somewhere. It gets set once and stays the same. You need to recalculate it every time.Either set
baywithin the loop, or in the condition of the while.Edit:
From your comment, you want to be able to reference this output later. You can go back to what you had, but inside of your blocking loop, put your
bay=$(prog -some flags)command inside of the loop. It will stick around for you to use later.