Bash Script Not Exiting...

Lupo, Kelly KLupo at allsector.com
Tue Jul 13 13:49:53 UTC 2010


I know this isn't exactly a scripting list, but the scripting forum I posted to didn't answer except to point out that I forgot scripting tags in my post....  :(  Maybe someone here has some experience that can help...

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 go to "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 close. (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! 

 

Kelly Lupo | Jr. Network Engineer
AllSector Technology Group

( T: 212.366.8488   F: 212.366.8422
* klupo at allsector.com | www.allsector.com 
 

-----Original Message-----
From: redhat-sysadmin-list-bounces at redhat.com [mailto:redhat-sysadmin-list-bounces at redhat.com] On Behalf Of Lupo, Kelly
Sent: Tuesday, July 13, 2010 9:20 AM
To: 'redhat-sysadmin-list at redhat.com'
Subject: RE: configuring a port number

Don't forget to open it in the firewall!

 

Thank you, 

Kelly Lupo | Jr. Network Engineer
AllSector Technology Group

( T: 212.366.8488   F: 212.366.8422
* klupo at allsector.com | www.allsector.com 
 

-----Original Message-----
From: redhat-sysadmin-list-bounces at redhat.com [mailto:redhat-sysadmin-list-bounces at redhat.com] On Behalf Of Ben
Sent: Tuesday, July 13, 2010 5:36 AM
To: redhat-sysadmin-list at redhat.com
Subject: Re: configuring a port number

On Tue, 13 Jul 2010, Chandrakant Reddy wrote:

> Hi
>    I want to run an application on a particular port number. What 
> changes i have to make to my system to run that application.

I think the best thing to do would be to change the port number in your application to the one you want to use and restart it.

Good luck with that.

Ben
--
Unix Support, MISD, University of Cambridge, England Plugger of wire, typer of keyboard, imparter of Clue
         Life Is Short.          It's All Good.

--
redhat-sysadmin-list mailing list
redhat-sysadmin-list at redhat.com
https://www.redhat.com/mailman/listinfo/redhat-sysadmin-list



--
redhat-sysadmin-list mailing list
redhat-sysadmin-list at redhat.com
https://www.redhat.com/mailman/listinfo/redhat-sysadmin-list






More information about the redhat-sysadmin-list mailing list