Bash Script Not Exiting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash Script Not Exiting
# 1  
Old 07-05-2010
Question Bash Script Not Exiting

I have a script planned for the Helpdesk to allow them to (on a couple of RHEL 3 / RHEL 5 servers) reset passwords, stop / start printers, and clear print queues. The appropriate sudo permissions were given to their accounts, and the individual functions all work just fine. The ability to move between functions (after resetting a password, it asks if you want to reset another yes/no/quit - no takes you back to the menu to select another function), at least looks like it's working in that it does let you go back to the main menu and select a different option.

The problem is that if you move between functions and eventually type "quit", it just dumps you back into whatever the previous function you picked was. (It *should* exit everything and actually close their ssh connection since they don't have access to the command line.) If you then deal with whatever you selected previously (IE: to reset another password), and at the end, choose quit again, for as many times as you switched functions, it will eventually work as expected. (If you switched functions 3x, you will have to quit 3x.)

I suspect this might be because I broke the script up so I didn't have to keep invoking the .bash_profile file every time they wanted to switch functions. (Can you even do that with all of the other variables and such being set there? Should I be doing that?)

I am very new to scripting, so this issue may also be due to how I'm actually scripting it... (Should be in a do-while loop, etc.) This is the relevant parts of what I have.

The .bash_profile:
Code:
# Choose activity
#
${ECHO}
${ECHO} "Choose what you would like to do"
${ECHO} "    1 - Change Password"
${ECHO} "    2 - Clear Print Queue"
${ECHO} "    3 - Stop Printer and Reject Jobs"
${ECHO} "    4 - Start Printer and Accept Jobs"
${ECHO} "    5 - Log out"
${ECHO} "Option: "
read ans
case $ans in
        1) sudo /usr/bin/password2
           exit
           ;;
        2) sudo /u/.scripts/printer
           exit
           ;;
        3) sudo /u/.scripts/stopprinter
           exit
           ;;
        4) sudo /u/.scripts/startprinter
           exit
           ;;
        *) exit
           ;;
esac



The stopprinter, etc, scripts (all have the same lines but with a different echo output):
Code:
# Ask if they want to do another one
echo
   echo -e "Would you like to disable another printer (y/n/q(uit)): "
   read ans
   case $ans in
   q|Q|quit) exit ;;
   n|N) /u/.scripts/continue ;;
   esac


The continue script is the same as the .bash_profile, except instead of ${ECHO} at the top, it just has echo...

Any assistance would be greatly appreciated! I know they can just hit ctrl + c to get out of it, but I'd rather it worked cleanly and the way it's supposed to...

Thanks!

Moderator's Comments:
Mod Comment Please use code tags, ty


Edit: Sorry! I didn't see the tag button above... Will do from now on. Thanks!

Last edited by tearsong; 07-06-2010 at 04:59 PM.. Reason: Newbness...!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

AIX bash script - exiting freezed telnet

Hallo all I'm writing a little shellscript in aix in order to test the correct connection to a specific ip-port. I'm using the sleep|telnet combination. All works great if connection is already open.. But if telnet connection are in trying state... It doesn't exit and all the rest of the script... (4 Replies)
Discussion started by: libeccio
4 Replies

2. Shell Programming and Scripting

Help for exiting the function not script

function2() { cmd1 cmd2 cmd3 .... cmdn } function2() { cmd11 cmd12 cmd13 .... .... } for i in {1,2} (7 Replies)
Discussion started by: yanglei_fage
7 Replies

3. Shell Programming and Scripting

Exiting from the script abruptly

Hi Team, Need your help for the below code snippet. I wrote a module to read the file names remote server using file name convention. Issue : My script is coming out from while loop without reading complete file. test1() { while read line do echo $line file_nm_convention=`echo... (3 Replies)
Discussion started by: gvkumar25
3 Replies

4. Shell Programming and Scripting

Exiting out of the script

I have to write a script in ksh which again should call another script. Say A.ksh is calling B.ksh. Now in B.ksh if the condition we are checking for is true then we have to go back to the main script A.ksh or if the condition in B.ksh is false then we have to totally come out of the scripts. I... (1 Reply)
Discussion started by: vpv0002
1 Replies

5. Shell Programming and Scripting

exiting from script

Hi, I am trying to exit the script from a function. I was in assumption that if we use exit ( inside or outside the function) it will exit from the script. alternatively, return will exit from that particular function. but in my case, exit is exiting from the function and not the script.... (8 Replies)
Discussion started by: shellwell
8 Replies

6. Shell Programming and Scripting

Exiting a script

I have a script abc.sh. Its contents are as follows: (7 Replies)
Discussion started by: lassimanji
7 Replies

7. Shell Programming and Scripting

exiting from script

there are many script in my project.i am having a problem when i am trying to quit from child script.what is the command to wrap up all the parent script and calling script as well? exit 0 is not working.please help.... (1 Reply)
Discussion started by: arghya_owen
1 Replies

8. Shell Programming and Scripting

Exiting from script when error occurs

Hi Friends, Is it possible to exit nicely(ie, to echo a message with the error occurred) from a shell script(quiet a big one :)) once it encounter an error in between the lines? For example, in my script I am calling the command mkdir and sometimes (when the directory already exists) it... (4 Replies)
Discussion started by: Sreejith_VK
4 Replies

9. Shell Programming and Scripting

Bash: Exiting while true loop when terminal is not the focus window

I am running an Ubuntu Gutsy laptop with Advanced Compiz fusion options enabled. I am using xdotool to simulate keyboard input in order to rotate through multiple desktops. I am looking for a way to kill a while true loop when the Enter key (or Control+C if it is easier) is pushed when the... (2 Replies)
Discussion started by: acclaypool
2 Replies

10. Shell Programming and Scripting

Shell script not exiting Gracefully

Hi we are seeing strange behaviour , when we execute shell script it is successfully executing but it's PID is still hanging when we see ps -ef | grep script1.ksh until we do Kill <PID> $script1.ksh $ $ ps -ef | grep script1.ksh user1 249996 1 0 10:48:40 pts/1 0:00... (5 Replies)
Discussion started by: smithK
5 Replies
Login or Register to Ask a Question