Shell script menu for end user - difficult challenge


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script menu for end user - difficult challenge
# 1  
Old 10-18-2011
CPU & Memory Shell script menu for end user - difficult challenge

Hello,

I need to make shell script menu for my end users. There is like 100 scripts in system, and they need to run that scripts true one main script with user friendly menu.

Example, when user will run main menu script, it will get something like this on his screen:
_________________________________________________________

Please insert number of steps?
User: 3

Insert step 1?
User: script47.sh
Insert check return code for script1.sh?
0

Insert step 2?
User: script78.sh
Insert check return code for script78.sh?
1

Insert step 3?
User: script34.sh
Insert check return code for script34.sh?
0
_________________________
Check before running the scripts:
1. Step: script1.sh -- return code 0
2. Step: script78.sh -- return code 1
3. Step: script34.sh -- return code 0
For continue insert yes
User: yes
**************************
Then script executing look like this
/app/test/script47.sh
chk_rc_100
/app/test/script78.sh
chk_rc_100
/app/test/script34.sh
chk_rc_100
_________________________________________________________

This is example of main script if you make it with fixed parameter, this is like some plan of executing, but i need to make menu so user can pick how many script will run and enter scripts name. Check return code is same for every case.

Code:
#Check for RC=100 
chk_rc_100() {
        ret_code=$?
        if [ "$ret_code" != "100" ]
                then
                        echo "!!!!!"
                        echo "Script finished with error!"
                        echo "!!!!!"
                        exit $ret_code
                fi
                fi
}


CMD="/app/test/script47.sh"
$CMD
chk_rc_100

CMD="/app/test/script27.sh"
$CMD
chk_rc_100

CMD="/app/test/script31.sh"
$CMD
chk_rc_100

CMD="/app/test/script79.sh"
$CMD
chk_rc_100


Last edited by waso; 10-19-2011 at 04:44 AM..
# 2  
Old 10-18-2011
How about this:

Code:
#!/bin/bash
while true
do
   printf "Please insert number of steps? "
   read steps
   [ "$steps" -gt 0 ] 2> /dev/null && break
   printf "Invalid number - please try again\n\n"
done
step=1
while [ $step -le $steps ]
do
  printf "Insert Step $step? "
  read step_cmd[step]
  if [ -f "${HOME_DIR}/bin/${step_cmd[step]}" ]
  then
      let step=step+1
      while true
      do
           printf "Please check return code for ${step_cmd[step]}? "
           read step_ret[step]
           [ "${step_ret[step]}" -ge 0 ] 2> /dev/null && break
           printf "Invalid number - please try again\n\n"
      done
      printf "\n"
  else
      printf "Illegal step script not found - please try again\n\n"
  fi
done
 
printf "Check before running the scripts:\n"
i=1
while [ $i -le ${#step_cmd[*]} ]
do
   printf "  %d. %s -- return code %d\n" $i ${step_cmd[i]} ${step_ret[i]}
   let i=i+1
done
printf "For continue insert yes: "
read continue
if [ "$continue" = "yes" ]
then
    i=1
    while [ $i -le ${#step_cmd[*]} ]
    do
       sudo -u root ${HOME_DIR}/bin/${step_cmd[i]}
       if [ $? -ne ${step_ret[i]} ]
       then
           echo "Script #$i failed - exiting"
           exit 2
       fi
       let i=i+1
    done
else
    echo "Not confirmed - aborting"
    exit 1
fi


Last edited by Chubler_XL; 10-18-2011 at 10:44 PM..
# 3  
Old 10-19-2011
Chubler_XL thanks for response, i have try your script, but it will run just for step 1.

I add some notes in first post, and make example of script with fixed parameters
# 4  
Old 10-19-2011
Can you post the output you are getting?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automate the menu options using shell script

I have a menu option which will look as follows Select a menu option 1.change password 2.login as root user 3.show system version 4.quit Select> 1 please enter the new password: unix reenter the new password: unix press any key to enter (then displays again the menu options to enter the... (4 Replies)
Discussion started by: shivakumar6g
4 Replies

2. Shell Programming and Scripting

Menu shell script help

Hi All, I have written a shell script that show menu driven option. My requirement is that in the menu driven option i want to select multiple choice. i.e if i want to select 1 or 1,2 or 1,2,3 or 2,3 etc .... Can some one help me in that My script. while true; do echo " " ... (8 Replies)
Discussion started by: Nawrajesh
8 Replies

3. Shell Programming and Scripting

A selection menu in a shell script

I'm writing a shell script and have a problem with selection when I issue the command, is there a way to automatically choose a selection number one after a selection menue appear Command 1-choice 2- choice 3-choice Thanks Sara (3 Replies)
Discussion started by: Sara_84
3 Replies

4. Shell Programming and Scripting

Shell script menu for end user - difficult challenge 2

Hello, I need to make shell script menu for my end users. There is like 100 scripts in system, and they need to run that scripts true one main script with user friendly menu. Example, when user will run main menu script, it will get something like this on his screen:... (1 Reply)
Discussion started by: waso
1 Replies

5. Shell Programming and Scripting

Shell script menu problem

I have tried searching the forum but i haven't found a solution for this. I have a shell script that presents the users with menus. The menus branch out to sub menus. It is all hunky dory as long as i traverse forward. But if i am in a sub menu and return to the previous menu and choose any... (11 Replies)
Discussion started by: goddevil
11 Replies

6. Shell Programming and Scripting

Menu using shell script

Hi, I need to have a shell script for the below need. 1. Menu with one heading and 4 options. 2. the heading and 4 options are taken from a file. File entry ====== Heading1|option1|option2|option3|option4| Heading2|option1|option2|option3|option4| 3. the user entries must be captured in... (9 Replies)
Discussion started by: umastinu
9 Replies

7. Shell Programming and Scripting

Shell script menu

hi guys, how would you do the following? I have a menu with 5 options in my shell script: 1. Run function 1 against files 2. Run function 2 against files 3. Run function 3 against files 4. Run function 4 against files 5. Run function 5 against files I'd like to be able to run multiple... (10 Replies)
Discussion started by: rich@ardz
10 Replies

8. Shell Programming and Scripting

need shell script for this challenge problem

two tabulate files (A, B), each contents thousands and thousands lines with ids. first find out contents with common ids in both A, B and print out into a file; second find out contents with ids which only exist in file A and print out into a file. (4 Replies)
Discussion started by: ssshen
4 Replies

9. Shell Programming and Scripting

Unix Shell Script: With Menu Option

I am attempting to create a shell script with the following capaciblities: 1. Listed options to choice from 2. Use to perform awk statements 3. Print a report with the awk results My questions are 1. How do I select more than one file for option #5 and #6 2. How to I create an... (11 Replies)
Discussion started by: jroberson
11 Replies
Login or Register to Ask a Question