Menu driven script.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Menu driven script.
# 1  
Old 05-31-2011
Menu driven script.

I'm a beginner at scripting and have been putting this script together over the past week. It's no where as polish as it could be. Any tips/suggestions on improving this script would be appreciate it. Every week, my team develops WAR files in tomcat on our test environment and moves them to our production environment. The script is to suppose automated the process. I put comments in each section to explain what it’s supposed to do. The only thing I can’t figure out is how to keep the script continue running until the #5 is enter to exit the script. I would like to run each portion of the script and have it go back to the menu so I can input the next number. Right now, after I run numbers 1-4 after the command is run, I need to execute the script again.


Code:
#!/bin/sh


### To Start and Stop Tomcat

f1 () {

while :
do
echo "Do you want to startup or shutdown Tomcat?"
echo "* [start] Startup Tomcat *"
echo "* [stop] Shutdown Tomcat *"
echo "Enter your choice : "
read input
case $input in

start) su - tomcat /usr/local/apache-tomcat-7.0.8/bin/startup.sh
    break;;
stop) su - tomcat /usr/local/apache-tomcat-7.0.8/bin/shutdown.sh
    break;;
*) echo "Invalid Choice";

echo "Press Enter to continue: " ; read ;;
esac
done
}

f2 () {

### renames the hostname and doain in the tomcat properties files our test machines to our prodution machine names

HOSTNAME=`hostname`

sed -i "s/prime.test.domain/$HOSTNAME/g" *.properties*
sed -i "s/prime/$HOSTNAME/g" *.properties*
sed -i "s/jazz.test.domain/$HOSTNAME/g" *.properties*
sed -i "s/jazz/$HOSTNAME/g" *.properties*
}


f3 () {

### deploys the WAR files to tomcat.  All WAR and properties files are copied to the deploy directory from our test network.

CONFIG=/opt/test/config
DEPLOY=/opt/test/deploy
TOMCAT=/usr/local/apache-tomcat-7.0.

\rm -R $TOMCAT/webapps/*.war $TOMCAT/webapps/Leo*
\rm -R $TOMCAT/work/Catalina/localhost/Leo*

cp $DEPLOY/*.war $TOMCAT/webapps
cp $DEPLOY/*.properties $CONFIG

chown -R user:group $TOMCAT $CONFIG
}

f4 () {

###Create a mysql database

MYSQLADM="root"
TESTADM="testuser"
TESTPW="password"

echo "Enter database name"
read dbname
echo "Enter MYSQLPW Password "
read -s MYSQLPW

mysql -u "$MYSQLADM -p"MYSQLPW" mysql -e "create database $dbname; grat all privileges on $dbname.* to $TESTADM@'localhost;"

echo "Database $dbname has been created"

}


f5 () {

exit
}

echo "Enter Choice:

1) Startup/shutdown Tomcat:
2) Replace Test names with production names:
3) Delete and Deploy new WAR Files:
4) Create new mysql database:
5) Exit:"

read choice

set -- $choice

for i in $@
do
#    echo "run function $i"
    f${i}
done


Last edited by pludi; 06-01-2011 at 01:37 AM..
# 2  
Old 06-06-2011
Code:
f5 () {
exit
}

exit will stop and exit from the script.

So what do you want to do after choice 5?

If you want to keep the script running, you can replace exist to continue.
# 3  
Old 06-06-2011
Thank you for the followup.

What I want the script to do is keeping repeating it's self until the exit is called in f5. For example, when the user selects 1 to start/stop tomcat. After that command is executed, I want the script to go back to the menu to allow the user to input another option. Right now, after 1 is select, I need to rerun the script to get the menu back.

Thanks
# 4  
Old 06-06-2011
put for loop in while endless loop.

Code:
while true
do
  echo "Enter Choice:

  1) Startup/shutdown Tomcat:
  2) Replace Test names with production names:
  3) Delete and Deploy new WAR Files:
  4) Create new mysql database:
  5) Exit:"

  read choice

  set -- $choice

  for i in $@
  do
  #    echo "run function $i"
      f${i}
  done

done

# 5  
Old 06-07-2011
That did the trick. Thank you for your assistance.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using menu driven script

Hi Team , I wrote a shell script for adding and subtracting two numbers am getting error could some one please help to fix it script: echo "Enter 1 to add:" echo "Enter 2 to sub:" echo "Enter 3 for both addition and subtraction :" read ans; case "$ans" in 1)... (4 Replies)
Discussion started by: knz
4 Replies

2. Shell Programming and Scripting

Menu Driven Bash Shell Script with Default Option

Hi All, I have written a menu driven bash shell script. Current Output is as below: ------------------------------------- Main Menu ------------------------------------- Option 1 Option 2 Option 3 Option 4 Exit ===================================== Enter your... (3 Replies)
Discussion started by: kiran_j
3 Replies

3. Shell Programming and Scripting

Execution Problem with dispalying file content using menu driven script

HI All.. below is my menu options script. in option 2,3 and 4 im giving input and they are saving into their respective text file. problem is when im trying to "cat" those files in options 7,8 and 9 im not getting the output. no respective file contents are displaying on screen. but if i... (1 Reply)
Discussion started by: saichand1985
1 Replies

4. Shell Programming and Scripting

Use of stty vs trap in script-driven login menu

My employers would like me to selectively run one of several different (already-existing) Korn Shell menu-driven scripts out of the user's .profile file, depending on some yet-to-be-specified user critieria. I've never done this kind of thing, but I have the existing scripts (among other... (5 Replies)
Discussion started by: Clovis_Sangrail
5 Replies

5. Shell Programming and Scripting

Help needed in writing a menu driven script

Hi, I was wondering if someone could help me write a shell script in Linux that backsup/restores data to anywhere I choose but it needs to be menu driven? Thanks, I'm new to Linux/Unix but liking it so far...just hoping to get to grips with the scripts! :) (7 Replies)
Discussion started by: Nicole
7 Replies

6. UNIX for Dummies Questions & Answers

What is a menu or command line option driven script?

i'm confused what this means. i was asked to design a menu or command line option driven script that reads out of a DB and displays info such as read_data.pl -u <user> -e <event> which would print commands run by <user>with the <event> in the db. any suggestions? i've been using... (2 Replies)
Discussion started by: kpddong
2 Replies

7. SuSE

Write shell script using menu-driven approach to show various system

QUESTION: Write shell script using menu-driven approach to show various system configuration like 1) Currently logged user and his logname 2) Your current shell 3) Your home directory 4) Your current path setting 5) Your current working directory 6) Show Currently logged number of... (1 Reply)
Discussion started by: bboyjervis
1 Replies

8. Shell Programming and Scripting

Menu driven Script needed ..pls help

Hi Guys.. am new to unix scrpiting..I need a Menu need to create using shell scrpting eg: Food items ready paid if i press "f" need to add items for a file food items.. if i press "r" it need to move into ready and remove from food items if i press "p" need to update a filed in... (1 Reply)
Discussion started by: sasdua
1 Replies

9. Shell Programming and Scripting

Assigning values to reference variables for a dynamic menu driven script.

How do I assign values to reference variables? I am assigning a variable name to --> $user_var Then I am trying to change its underlying variable value by $((user_var))=$user_value .. its failing,, Please let me know if there is a way to do this dynamically.. FileA.props... (5 Replies)
Discussion started by: kchinnam
5 Replies

10. Homework & Coursework Questions

Menu Driven Shell Script which accepts1 to 5 options

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 1) Write a Menu Driven Shell Script which accepts1 to 5 options and performs the following actions for... (1 Reply)
Discussion started by: vaghya
1 Replies
Login or Register to Ask a Question