1831478 Members
3272 Online
110025 Solutions
New Discussion

Re: scripts query

 
Sir T S S
Advisor

scripts query

Hi all,

i test a script to let say enter x option to exit the from the shell,

for e.g
case $i in
x|X) exit ;;

but when i choose x or X , i want it to logout from the operation menu but it only go out to the shell prompt.. what modification is needed.
15 REPLIES 15
Indira Aramandla
Honored Contributor

Re: scripts query

Hi Sri,

You need this

case $i in
x|X) exit ;;

esac


IA
Never give up, Keep Trying
Fred Ruffet
Honored Contributor

Re: scripts query

use break instead of exit. It will break the current loop, and wil continue with the "clear" command.

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Michael_356
Frequent Advisor

Re: scripts query

Hi there,

if i understand it right, you want to exit from shell if option 'x' is choose?
Then you have to insert this script as shell for the user in /etc/passwd instead of a OS-shell.

regards

Michael
Thierry Poels_1
Honored Contributor

Re: scripts query

hi,

if it is a menu script then use
"exec menu.ksh" instead of "ksh menu.ksh".
By doing this the current shell is replaced by the script, so exiting the script will force a logout.

Try using "logout" instead of "exit".

regards,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Nguyen Anh Tien
Honored Contributor

Re: scripts query

REPLACE "exit" by "break" AT
1) System_menu ;;
x|X) break ;;
*) eczho
echo Invalid choice.
echo Try again.
sleep 1
echo ;;
esac
done
Read this doc for more detail (Shell User's Guide)
www.docs.hp.com/en/B2355-90046
Regard
tienna
HP is simple
Sanjay Kumar Suri
Honored Contributor

Re: scripts query

I think break command exits loops created by the keywords for, while, until, or
select.

Put your case structure in a dummy while/until loop.

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
twang
Honored Contributor

Re: scripts query

The code works, you may take a look at it,
#! /usr/bin/sh
while : ; do
clear
read OPT
case $OPT in
[x,X])
exit 0
;;
esac
done
Sir T S S
Advisor

Re: scripts query

i try all the method & it only bring me out to shell, i intend that when it get an x option and it will logout from shell.
Fred Ruffet
Honored Contributor

Re: scripts query

Maybe you should put your script as a shell for the user.

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Sanjay Kumar Suri
Honored Contributor

Re: scripts query

Agree with Fred.

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Sanjay Kumar Suri
Honored Contributor

Re: scripts query

Another way is get the pid of the shell with grep etc and then use

kill -9 pid

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Michael_356
Frequent Advisor

Re: scripts query

Hi there,

as i said before and agreeing with Fred:

Set your script in /etc/passwd as a shell for the involved user.

instead
user1:*:217:200:full name,location,:/home/user1:/usr/bin/csh

to

user1:*:217:200:full name,location,:/home/user1:/home/user1/scriptname

Regards

Michael
Thierry Poels_1
Honored Contributor

Re: scripts query

hmmm, you did not try everything....

try "exec menu.sh"
instead of "sh menu.sh".

regards,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Geoff Wild
Honored Contributor

Re: scripts query

You want to use break...

Here's a menu I use:

# cat lp.mnu
#!/bin/sh
# lp.mnu
# A menu to assist in supporting the lp spooler
# Geoff Wild
# March 20 2002
# Main logic starts at MAIN LOGIC
# The logo will be displayed at the top of the screen6.
LOGO="GEUNIX LP Support Menu"
#------------------------------------------------------
# MENU PROMPTS
#------------------------------------------------------
# A list of menu prompts to be displayed for the user.
# The list can be modified.
# In this first list, enter the menu prompt as it should appear
# on the screen for each of the letters A - L. In this example
# menu pick variables emenu through lmenu are blank as there
# are no menu selections for keys E through L.
amenu="a. Check printer status" ;
bmenu="b. Add Printer" ;
cmenu="c. Delete Printer" ;
dmenu="d. Disable a Print Queue" ;
emenu="e. Enable a Print Queue " ;
fmenu="f. Backup the Spooler Configuration" ;
gmenu="g. Restore the Spooler Configuration" ;
hmenu="h. Check the Print Spooler log " ;
imenu="i. Check the iprprtpkg log " ;
jmenu="j. Check the iprprtpkg status " ;
kmenu=" " ;
lmenu=" " ;
#------------------------------------------------------
# MENU FUNCTION DEFINITIONS
#------------------------------------------------------
# Define a function for invalid menu picks
# The function loads an error message into a variable
badchoice () { MSG="Invalid Selection ... Please Try Again" ; }
# For each prompt displayed above, there is a list of
# commands to execute in response to the user picking the
# associated letter.
# They are defined as functions
# apick () through lpick () where
# apick () corresponds to the menu
# prompt amenu which is selected
# selected by pressing a or A.
# bpick () corresponds to the menu
# prompt bmenu which is selected by
# pressing b or B and so on.
# Any menu item that is not
# assigned a set of commands, is
# assigned
# the function badchoice () as a default for that pick.
# If the user
# selects a menu key that is assigned
# to badchoice (). This function
# causes an error message to be
# displayed on the screen.
# To add items to this second
# list, replace badchoice ()
# with the commands to run when
# that letter is pressed.
# The following steps simply define
# the functions, but do not cause
# any shell program steps to be executed.
apick () { echo enter queue to check ; read Q ; /opt/hpnpl/bin/lpst $Q | more ; }
bpick () { /usr/local/bin/lp.queue.mnu ; }
cpick () { echo coming soon ; sleep 5;}
dpick () { echo Enter queue name ; read Q ; /usr/bin/disable $Q ; sleep 5; }
epick () { echo Enter queue name ; read Q ; /usr/bin/enable $Q ; sleep 5 ; }
fpick () { echo Backing up the spooler configuration to /var/sam/lp/lp.new....please wait...; /usr/sam/lbin/lpmgr -S -v -xsavedir=/var/sam/lp/ ; cp -r -p /var/sam/lp/lp.new/* /var/sam/lp/ ; echo Press Enter To Return to Menu... ;read DUMMY ; }
gpick () { echo LAST CHANCE - you have 5 seconds to abort - ctrl c to abort ; sleep 5 ; echo Restoring the spooler configuration....please wait...; /usr/sam/lbin/lpmgr -R -xsavedir=/var/sam/lp/ ; echo Press Enter To Return to Menu... ;read DUMMY ; }
hpick () { tail -200 /var/spool/lp/log |more ; echo Press Enter To Return to Menu... ; read DUMMY ;}
ipick () { tail -200 /etc/cmcluster/IPRPRT/iprprt.cntl.log |more ;echo Press Enter To Return to Menu... ; read DUMMY ; }
jpick () { cmviewcl ;echo Press Enter To Return to Menu... ; read DUMMY; }
kpick () { badchoice ; }
lpick () { badchoice ; }
#------------------------------------------------------
# DISPLAY FUNCTION DEFINITION
#------------------------------------------------------
# This function displays the menu.
# The routine clears the screen, echoes
# the logo and menu prompts
# and some additional messages.
# Note that this definition does
# not cause the function to
# be executed yet, it just defines
# it ready to be executed
themenu () {
# clear the screen
clear
echo `date`
echo
echo "\t\t\t" $LOGO
echo
echo "\t\tPlease Select:"
echo
echo "\t\t\t" $amenu
echo "\t\t\t" $bmenu
echo "\t\t\t" $cmenu
echo "\t\t\t" $dmenu
echo "\t\t\t" $emenu
echo "\t\t\t" $fmenu
echo "\t\t\t" $gmenu
echo "\t\t\t" $hmenu
echo "\t\t\t" $imenu
echo "\t\t\t" $jmenu
echo "\t\t\t" $kmenu
echo "\t\t\t" $lmenu
echo "\t\t\tx. Exit"
echo
echo $MSG
echo
echo Select by pressing the letter and then ENTER ;
}
#------------------------------------------------------
# MAIN LOGIC
#------------------------------------------------------
# Every thing up to this point has been to define
# variables or functions.
# The program actually starts running here.
# Clear out the error message variable
MSG=
# Repeat the menu over and over
# Steps are:
# 1. Display the menu
# 2. 'read' a line of input from the key board
# 3. Clear the error message
# 4. Check the answer for a or A or b or B etc. and dispatch
# to the appropriate program or function or exit
# 5. If the entry was invalid call the badchoice () function
# to initialize MSG to an error message
# 6. This error message is used when setting up the menu
# for a menu pick that is valid but has no command
# associated with it.
while true
do
# 1. display the menu
themenu
# 2. read a line of input from the keyboard
read answer
# 3. Clear any error message
MSG=
# 4. Execute one of the defined functions based on the
# letter entered by the user.156.
# 5. If the choice was E through L, the pre-defined
# function for that pick will execute badchoice ()
# which loads an error message into MSG
case $answer in
a|A) apick;;
b|B) bpick;;
c|C) cpick;;
d|D) dpick;;
e|E) epick;;
f|F) fpick;;
g|G) gpick;;
h|H) hpick;;
i|I) ipick;;
j|J) jpick;;
k|K) kpick;;
l|L) lpick;;
# If the user selects =91x=92 to exit then break out
# of this loop
x|X) break;;
# 6. If the entry was invalid call the badchoice function
# to initialize MSG to an error message
*) badchoice;;
esac
# Do it again until the user enters =91x=92.
done


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Sir T S S
Advisor

Re: scripts query

thanks.