Script to selct an option


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to selct an option
# 1  
Old 11-24-2006
Script to selct an option

Dear experts,

Im trying to create a script which will allow me to do the following:

1) log in with a username and password.

2) select an option.

this is how the menu looks:

Select one of the following options:

1 - Activation Menu
2 - Troubleshooting Menu
3 - New Window
4 - Database Creation
5 - Database Maintenance

q - Quit

Enter option number --->

Any good suggestions/ links where i can get a headstart?

Thanks.



Wee
# 2  
Old 11-24-2006
Here is the code to display a menu:
Code:
#!/bin/sh

while [ 1 ]
do
        clear
        echo Menu:
        echo 1 - Activation Menu
        echo 2 - Troubleshooting Menu
        echo 3 - New Window
        echo 4 - Database Creation
        echo 5 - Database Maintenance
        echo
        echo q - Quit
        echo
        echo -n Please enter your option:
        read CHOSEN_KEY
        case $CHOSEN_KEY in
                1)      echo You chose 1
                        break;;
                2)      echo You chose 2
                        break;;
                3)      echo You chose 3
                        break;;
                4)      echo You chose 4
                        break;;
                5)      echo You chose 5
                        break;;
                q)      echo Bye bye
                        exit;;
        esac
done

# 3  
Old 11-24-2006
hi fongthai,

many thanks for the help but this is not what i want. maybe i did not phase myself clearly.

the menu has been created and been running fine.

right now im trying to write a script where i can call this menu up and make the selection.

reason being some of the services may not be runningi fine so i need to monitor and activate those service in time when they are down.

thanks again.

wee

Quote:
Originally Posted by fongthai
Here is the code to display a menu:
Code:
#!/bin/sh

while [ 1 ]
do
        clear
        echo Menu:
        echo 1 - Activation Menu
        echo 2 - Troubleshooting Menu
        echo 3 - New Window
        echo 4 - Database Creation
        echo 5 - Database Maintenance
        echo
        echo q - Quit
        echo
        echo -n Please enter your option:
        read CHOSEN_KEY
        case $CHOSEN_KEY in
                1)      echo You chose 1
                        break;;
                2)      echo You chose 2
                        break;;
                3)      echo You chose 3
                        break;;
                4)      echo You chose 4
                        break;;
                5)      echo You chose 5
                        break;;
                q)      echo Bye bye
                        exit;;
        esac
done

# 4  
Old 11-28-2006
hi,

may I suggest you have a while loop script which does a several checks and assign these values to flatfiles. Then followed by 'if' or case conditions which test against these flastfiles. Finally su - someuser whose .profile is modified to fireoff some script.

I have a similiar script but not 'case' which I run nohup'd on my boxes which wakes up every 300 seconds or 5mins to run these tests. If test condition confirms any dead process it will su - "bouncer", a user on my box which has a modified .profile to restart all my apps in proper sequence, otherwise it justs sends email alerts or do nothing just logging to nohup.out. Maybe u can modify it for your purpose.

good luck Smilie

#!/bin/sh
X1="datacenter@mydomain.com"
X2="teamlead@mydomain.com"
SUBJECT="Mydomain_Webserver_Status"
#
#
# test conditions
#
while true
do
rm -f /tmp/xb
rm -f /tmp/xn
httpcount=`ps -ef | grep -v grep | grep http | wc -l > /tmp/xb`
javacount=`ps -ef | grep -v grep | grep java | wc -l > /tmp/xn`
#
# First test
if (test `cat /tmp/xb` -gt "500") then
echo "Maxclient breached 500 webserver will be slow on `date`";
echo "Maxclient Breached 500 webserver will be slow on `date`" | mailx -s $SUBJECT $X1 $X2;
else echo "Maxclient is fine";
fi

# Second test
if (test `cat /tmp/xb` -eq "0") then
echo "Http process is zero on `date` restarting webserver";
echo "Http process is zero on `date` restarting webserver" | mailx -s $SUBJECT $X1 $X2;
/usr/bin/su - bouncer;
else echo "webserver running fine Http Count is `ps -ef |grep -v grep | grep http | wc -l`";
fi
#
# Third test
if (test `cat /tmp/xn` -ne "1") then
echo "appserver is dead bouncing webserver on `date`";
echo "appserver is dead bouncing webserver on `date`" | mailx -s $SUBJECT $X1 $X2;
/usr/bin/su - bouncer;
else echo "appserver is fine";
fi
sleep 300
done
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to call a menu script and redirect each option to a text file

Hello, I want to design a script that will call an existing menu script and select options one by one and redirict the out put to a file. For example;- In the script MENU.sh there are 10 options i want to design a script MENU2.sh that will select option 2 3 4 6 7 10 and redirict the output... (4 Replies)
Discussion started by: spradha
4 Replies

2. Shell Programming and Scripting

Call one script option to other in shell script

HI Guys, My Script abc.sh 1) Checks 2) CA Scipt 3) CIA Script 0) Exit Enter Choice : Now if i select choice 2 then after finshed choice 2 wait for 40 min and run choice 3 what i can write in CA Scipt option: if then My Code : ... (3 Replies)
Discussion started by: pareshkp
3 Replies

3. Shell Programming and Scripting

su option to use with pasword in script

Hi, I am trying to create warraper script to run a shell script in which can be run using particular user id only . I have deoded the user password thst user and wanted to pass while running inside shell script as below .Script should come back to same shell after executing screen_update.sh.... (2 Replies)
Discussion started by: anthriksh2000
2 Replies

4. UNIX for Advanced & Expert Users

Hi, can some one help in selecting option in script

Hi, Some one help in completing the script: I need to write a script which has to select automatically only one option(below case only D - ALL) out of all options instead of manual entry There is an script which is used to test number of connection to different db that it connects when we... (7 Replies)
Discussion started by: PAKumar
7 Replies

5. Shell Programming and Scripting

perl script command line option driven script

could someone show me a sample command line option driven script? i want to see an easy way to write one and how i can execute it using command line options such as typing in read.pl -i <id> -c <cmds> -s <start> -e <end> would read out all the commands run by ID . from start time to... (7 Replies)
Discussion started by: kpddong
7 Replies

6. Shell Programming and Scripting

Option 4 in script broken

Hi, I need some help with an issue on my script. When I run option 3 it works just fine. When I run Option 4 which puts back the changes done in option 3 it fails. Oddly enough when I run Option 4 right after it failed it seems to work. I am not sure why that is or is a false positive. In... (2 Replies)
Discussion started by: richsark
2 Replies

7. Shell Programming and Scripting

recently introduced to the newer option for find...does an older option exist?

To find all the files in your home directory that have been edited in some way since the last tar file, use this command: find . -newer backup.tar.gz Is anyone familiar with an older solution? looking to identify files older then 15mins across several directories. thanks, manny (2 Replies)
Discussion started by: mr_manny
2 Replies

8. Shell Programming and Scripting

Need help with script option

Hi, So my script reads $1 on the command line. example: SCRIPT_NAME 1111 In my script I use a nawk statement to grab $1 but I also need it to read $1 from the variable (1111 from command line in the example) nawk -F, '($1~1111)' *.$date.* What can I do so that this nawk statement... (2 Replies)
Discussion started by: llsmr777
2 Replies

9. Shell Programming and Scripting

\n option in script

I have a series of around 20 files as my program output. The final line of my script gets the no of files and the file list for the present day. The no of files shoudl be printed first and the files for today must be printed in the next line. Ialso understood that echo -e must be used for with \n.... (4 Replies)
Discussion started by: venkidhadha
4 Replies

10. Shell Programming and Scripting

option followed by : taking next option if argument missing with getopts

Hi all, I am parsing command line options using getopts. The problem is that mandatory argument options following ":" is taking next option as argument if it is not followed by any argument. Below is the script: while getopts :hd:t:s:l:p:f: opt do case "$opt" in -h|-\?)... (2 Replies)
Discussion started by: gurukottur
2 Replies
Login or Register to Ask a Question