1752565 Members
5235 Online
108788 Solutions
New Discussion юеВ

Menu script

 
SOLVED
Go to solution
John Pyle
Occasional Advisor

Menu script

I have written a script to execute commands to work with an EMC disk array BCV and the standard disks of two systems. The function of the script is to allow the user to select from a menu the commands necessary to perform a the association of the standard disks with the BCV, sync the disks, split the disks, import the BCV as a volume group and perform backups of the mounted disks. The main script calls other scripts that perform each of these specific functions. When these sub-scripts exit I would like to return to the main script. How can I execute these sub-scripts without having to incorporate the code for each of them in my main script? I made this work by calling the main script at the the end of the file. The problem with this is that when I perform multiple functions in the main script it spawns another process and the first script and each additional script are running until I exit. If someone has a script that will perform these tasks I would be interested in checking it out. I have attached the main script, please be kind I have only been a shell programmer for a few days or weeks. I would appreciate any help you could provide.

Thank You,

John
Administrators make better brewers
4 REPLIES 4
Rick Garland
Honored Contributor

Re: Menu script

Put in some return values
Paul Hite
Trusted Contributor
Solution

Re: Menu script

Put a loop around the body of your case statement. Just loop forever and allow the the exit statement on the q option to get you out. I have attached a revision of a portion of your script to illustrate this.
Tim Malnati
Honored Contributor

Re: Menu script

I did a similar thing for a client where three machines were involved. I would love to give you the code but there is a disclosure/ownership problem; I don't even have a copy myself. In this case the primary set is used for the production machine, one bcv set is used for backups on the second machine, and a third set is used on a development machine which has a secondary function of emergency failover in the event the production box dies.

For the most part, I tied the functioning and control of a particular bcv set with the machine that has primary use of it. First I remsh a command to the machine that needs to perform a particular function. For instance, in the case of a backup I commad the production machine to suspend writes to the database and message online users, telling them what's going on. I have NFS mounts between the machines where I set flags to indicate back to origin machine that a particular command evolution has completed. If the machine is dead and this is a failover situation, the flags are ignored. The originating script loops looking for this file flag and starts the split when it sees it. I have a timeout there to send a message to ops if the evolution takes too long. As soon as the split starts, I clear the flag and signal back to the production machine to resume processing. I then prepare and mount the bcv set on the machine that does the backups and away it goes. In actuality, this entire thing is completely automated with Maestro (not my choice) starting the whole chain of events .

At the time that all of this was written there was a limitation from EMC that would not allow more than one set of bcv's from being attached at any one time. Because of this I perform an extensive amount of bcv status commands and parse the output to determine the overall state of things. I added a lot of code to my scripts that would error based on the status prior to attempting to perform any illegal function (eg: can't mount a set that has not been split). In the case of a refresh for the test machine, I would have to split the backup set first, before I could sync up the refresh set. There were a variety of other options there too. Like keep the backup bcv's from resyncing while doing an upgrade to the production box until all was well. The key to it all was looping on the flags, lots of status checks, and lots of code there to handle most any error condition. It took a while to write and fully test all this stuff, but when the second machine group came around, it took less than a day to build from scratch and have it fully functional.
Kenneth Martin
Occasional Advisor

Re: Menu script

Setup a loop something like:

#!/bin/sh
# Run Bourne shell
#
# gohome.sh and getcoffee.sh are
# user supplied scripts.
#
banner "MY MENU"
while : ; do
echo " "
echo "0. Exit script"
echo "1. Go home"
echo "2. Get coffee"
echo "3. who is on"
echo "Select option number from above ?c"
read q
case "$q" in
0) echo "Exit"; exit ;;
1) sh gohome.sh ;;
2) sh getcoffee.sh ;;
3) echo "Who Is Logged On"
who -uH
echo " "
echo "Press ENTER c"
read w ;;
*) echo "$q option unknown";;
esac
done