exit a script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers exit a script
# 8  
Old 05-19-2010
I still see the same issue.

Let me know if you want me to try something else.

Thanks.
# 9  
Old 05-19-2010
OK,
Let me know wether you get the prompt after executing any of the subscripts or not.

Code:
<root># cat  a.ksh
      #!/bin/ksh
      echo "DIS QL(*) CURDEPTH WHERE(CURDEPTH GT 0)" | runmqsc QM1
 
<root># ./a.ksh      ----->> Are you getting prompt after sucessful execution or this script is waiting for any input.

Also post the o/p of your main script run with following command :

Code:
ksh -x YOUR_SCRIPT

It will give you a bit confusing output....

Well I am getting the script given by "zaxxon", executed sucessful..Smilie
# 10  
Old 05-19-2010
Code:
$ cat queuedepth.s
#!/bin/ksh
echo "DIS QL(*) CURDEPTH WHERE(CURDEPTH GT 0)" | runmqsc SESB001T
exit

Script output:
Code:
 
$./queuedepth.s
5724-H72 (C) Copyright IBM Corp. 1994, 2009.  ALL RIGHTS RESERVED.
Starting MQSC for queue manager QM1.
 
     1 : DIS QL(*) CURDEPTH WHERE(CURDEPTH GT 0)
AMQ8409: Display Queue details.
   QUEUE(SYSTEM.ADMIN.QMGR.EVENT)          TYPE(QLOCAL)
   CURDEPTH(1)
AMQ8409: Display Queue details.
   QUEUE(SYSTEM.AUTH.DATA.QUEUE)           TYPE(QLOCAL)
   CURDEPTH(121)
AMQ8409: Display Queue details.
   QUEUE(SYSTEM.CHANNEL.SYNCQ)             TYPE(QLOCAL)
   CURDEPTH(3)
AMQ8409: Display Queue details.
   QUEUE(SYSTEM.CLUSTER.REPOSITORY.QUEUE)
   TYPE(QLOCAL)                            CURDEPTH(23)
AMQ8409: Display Queue details.
   QUEUE(SYSTEM.DURABLE.SUBSCRIBER.QUEUE)
   TYPE(QLOCAL)                            CURDEPTH(1)
AMQ8409: Display Queue details.
   QUEUE(SYSTEM.HIERARCHY.STATE)           TYPE(QLOCAL)
   CURDEPTH(2)
AMQ8409: Display Queue details.
   QUEUE(SYSTEM.RETAINED.PUB.QUEUE)        TYPE(QLOCAL)
   CURDEPTH(4)
One MQSC command read.
No commands have a syntax error.
All valid MQSC commands were processed.


Here is the original Menu script:
Code:
 
$ cat queuedepth.s
#!/bin/ksh
echo "DIS QL(*) CURDEPTH WHERE(CURDEPTH GT 0)" | runmqsc SESB001T
exit
bash-3.00$
bash-3.00$
bash-3.00$ cat sample.s
#!/usr/bin/ksh
#export SHELL=''
PS3='Enter the options of your choice(x to exit)=>'
select useropt in         \
        'List queue depth' \
        'List queue connections' \
        'Continue'        \
        'Exit'
do
        case $REPLY in
                1 ) echo "Listing queue depth..."
                    queuedepth.s
                     ;;
                2 ) echo "Listing queue connections..."
                    queueconn.s
                     ;;
                x ) echo "Exiting...";
                    exit 0
                    ;;
                c ) continue
                    ;;
                * ) echo "\ninvalid number selected\n"
           ;;
        esac
$0
done
echo "Continue..."
exit 0

ksh -x sample.s (Menu script)
Code:
 
$ ksh -x sample.s
+ PS3=Enter the options of your choice(x to exit)=>
1) List queue depth
2) List queue connections
3) Continue
4) Exit
Enter the options of your choice(x to exit)=>1
+ echo Listing queue depth...
Listing queue depth...
+ queuedepth.s
5724-H72 (C) Copyright IBM Corp. 1994, 2009.  ALL RIGHTS RESERVED.
Starting MQSC for queue manager SESB001T.
 
     1 : DIS QL(*) CURDEPTH WHERE(CURDEPTH GT 0)
AMQ8409: Display Queue details.
   QUEUE(SYSTEM.ADMIN.QMGR.EVENT)          TYPE(QLOCAL)
   CURDEPTH(1)
AMQ8409: Display Queue details.
   QUEUE(SYSTEM.AUTH.DATA.QUEUE)           TYPE(QLOCAL)
   CURDEPTH(121)
AMQ8409: Display Queue details.
   QUEUE(SYSTEM.CHANNEL.SYNCQ)             TYPE(QLOCAL)
   CURDEPTH(3)
AMQ8409: Display Queue details.
   QUEUE(SYSTEM.CLUSTER.REPOSITORY.QUEUE)
   TYPE(QLOCAL)                            CURDEPTH(23)
AMQ8409: Display Queue details.
   QUEUE(SYSTEM.DURABLE.SUBSCRIBER.QUEUE)
   TYPE(QLOCAL)                            CURDEPTH(1)
AMQ8409: Display Queue details.
   QUEUE(SYSTEM.HIERARCHY.STATE)           TYPE(QLOCAL)
   CURDEPTH(2)
AMQ8409: Display Queue details.
   QUEUE(SYSTEM.RETAINED.PUB.QUEUE)        TYPE(QLOCAL)
   CURDEPTH(4)
One MQSC command read.
No commands have a syntax error.
All valid MQSC commands were processed.
+ sample.s
1) List queue depth
2) List queue connections
3) Continue
4) Exit
Enter the options of your choice(x to exit)=>

Let me know your thoughts.

Thanks.
# 11  
Old 05-19-2010
What really creating problem in your script is "$0" which you are calling every time loop is executed :

Code:
#!/usr/bin/ksh
#export SHELL=''
PS3='Enter the options of your choice(x to exit)=>'
select useropt in         \
        'List queue depth' \
        'List queue connections' \
        'Continue'        \
        'Exit'
do
        case $REPLY in
                1 ) echo "Listing queue depth..."
                    queuedepth.s
                     ;;
                2 ) echo "Listing queue connections..."
                    queueconn.s
                     ;;
                x ) echo "Exiting...";
                    exit 0
                    ;;
                c ) continue
                    ;;
                * ) echo "\ninvalid number selected\n"
           ;;
        esac
$0                         ------->>>> NOTICE THIS.
done
echo "Continue..."
exit 0

So, modify your script as follow :

Code:
#!/usr/bin/ksh
while true
do
abc()
{
cat <<!
1) List Processess
2) List semaphores
3) Continue
4) Exit
!
echo "Enter the options of your choice(x to exit)=>"
read REPLY
}
abc
        case $REPLY in
                1 ) echo "Listing queue depth..."
                        queuedepth.s
                              ;;
                2 ) echo "Listing queue connections..."
                          queueconn.s
                              ;;
                x ) echo "Exiting..."; exit 0 ;;
 
                * ) echo "\ninvalid number selected\n" ;;
        esac
done
exit 0


Hope this works for you....SmilieSmilie
Smilie
# 12  
Old 05-19-2010
Thanks for your help.

The script what you provided is working. Just need some polishing.

Code:
 
#!/usr/bin/ksh
while true
do
abc()
{
/usr/bin/clear
cat <<!
1) queue depth
2) queue connections
3) Continue
4) Exit
!
echo="Enter the options of your choice(x to exit)=> \c"
read REPLY
}
abc
        case $REPLY in
                1 ) echo "Listing queue depth..."
                        queuedepth.s
                              ;;
                2 ) echo "Listing queue connections..."
                          queueconn.s
                              ;;
                x ) echo "Exiting..."; exit 0 ;;
                c ) continue ;;
                * ) echo "\ninvalid number selected\n" ;;
        esac
         echo  "Press enter to continue:"
         read ANSWER
done
exit 0

Here is the output of the above script:
Code:
 
$ ./sample1_working.sh
1) List Processess
2) List semaphores
3) Continue
4) Exit
Enter the options of your choice(x to exit)=>
1
Listing queue depth...
5724-H72 (C) Copyright IBM Corp. 1994, 2009.  ALL RIGHTS RESERVED.
Starting MQSC for queue manager SESB001T.
 
     1 : DIS QL(*) CURDEPTH WHERE(CURDEPTH GT 0)
AMQ8409: Display Queue details.
   QUEUE(SYSTEM.ADMIN.QMGR.EVENT)          TYPE(QLOCAL)
   CURDEPTH(1)
AMQ8409: Display Queue details.
   QUEUE(SYSTEM.AUTH.DATA.QUEUE)           TYPE(QLOCAL)
   CURDEPTH(121)
AMQ8409: Display Queue details.
   QUEUE(SYSTEM.CHANNEL.SYNCQ)             TYPE(QLOCAL)
   CURDEPTH(3)
AMQ8409: Display Queue details.
   QUEUE(SYSTEM.CLUSTER.REPOSITORY.QUEUE)
   TYPE(QLOCAL)                            CURDEPTH(23)
AMQ8409: Display Queue details.
   QUEUE(SYSTEM.DURABLE.SUBSCRIBER.QUEUE)
   TYPE(QLOCAL)                            CURDEPTH(1)
AMQ8409: Display Queue details.
   QUEUE(SYSTEM.HIERARCHY.STATE)           TYPE(QLOCAL)
   CURDEPTH(2)
AMQ8409: Display Queue details.
   QUEUE(SYSTEM.RETAINED.PUB.QUEUE)        TYPE(QLOCAL)
   CURDEPTH(4)
One MQSC command read.
No commands have a syntax error.
All valid MQSC commands were processed.
Press enter to continue:

Right now the script is reading the REPLY value in next line as shown below:
Code:
Enter the options of your choice(x to exit)=>
1

Question:
Is it possible to read the REPLY value adjacent to 'Enter the options of your choice(x to exit)=>' like this:

Code:
Enter the options of your choice(x to exit)=>1

That makes the script more beautiful..:-)

Thanks.
# 13  
Old 05-19-2010
yaa you still need to make some modifications as follow :

Code:
#!/usr/bin/ksh
abc()
{
/usr/bin/clear
cat <<!
                        ###########  MENU  ##########
                        #                           #
                        #   1) queue depth          #
                        #   2) queue connections    #
                        #   x) Exit                 #
                        #   c) Continue             #
                        #                           #
                        #############################
!
printf "Enter the CHOICE from above MENU ("x" to exit)=> "
read REPLY
}
while true
do
abc
case $REPLY in
                1 ) echo "Listing queue depth..."
                        queuedepth.s
                              ;;
                2 ) echo "Listing queue connections..."
                          queueconn.s
                              ;;
                x ) echo "Exiting..."; exit 0 ;;
                c ) continue ;;
                * ) echo "\ninvalid number selected\n" ;;
          esac
           printf  "Press enter to continue:"
             read ANSWER
done
exit 0

Above modification will make the script a bit faster....SmilieSmilie
# 14  
Old 05-20-2010
Thanks a lot for all your inputs. Script looks great.
SmilieSmilieSmilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Exit from script

I am invoking java program from shell script. Is there way to catch internal error and exit from script. though it is logging exceptions and errors script continues. (2 Replies)
Discussion started by: sushma123
2 Replies

2. Shell Programming and Scripting

How to capture the exit code of a shell script in a perl script.?

hi, i want to pop up an alert box using perl script. my requirement is. i am using a html page which calls a perl script. this perl script calls a shell script.. after the shell script ends its execution, i am using exit 0 to terminate the shell script successfully and exit 1 to terminate the... (3 Replies)
Discussion started by: Little
3 Replies

3. Shell Programming and Scripting

How to capture exit code of child script and send it to parent script?

#!/usr/local/bin/bash set -vx /prod/HotelierLinks/palaceLink/bin/PalacefilesWait /prod/HotelierLinks/palaceLink/bin/prodEnvSetup 03212013 & if then echo "fatal error: Palace/HardRock failed!!!!" 1>&2 echo "Palace Failed" | mail -s "Link Failed at Palace/HardRock" -c... (1 Reply)
Discussion started by: aroragaurav.84
1 Replies

4. Shell Programming and Scripting

How to get the exit status of a command in nner script to the outer script?

Hi all, I have a shell script inside which i am executing another shell script. In the inner script im executing a command. i want the status of that command in the outer script to perform some validations. How to get its status please help!!1 Im using ksh. (2 Replies)
Discussion started by: Jayaraman
2 Replies

5. Shell Programming and Scripting

How to grep sql error in shell script and exit the script?

I need help in the following script. I want to grep the sql errors insert into the error table and exit the shell script if there is any error, otherwise keep running the scripts. Here is my script #!/bin/csh -f source .orapass set user = $USER set pass = $PASS cd /opt/data/scripts echo... (2 Replies)
Discussion started by: allinshell99
2 Replies

6. UNIX for Dummies Questions & Answers

trying to grep the first few lines of a continuos script, and exit the script anyidea

Hi. I am trying to extract the output of the first few lines of a continuos sh script. The when i run it, i wont to grep the the first 20 lines of it for an entry and basically do a crtl z out of it or to that effect, and output the results to a text file. I basically want to script... (5 Replies)
Discussion started by: k00061804
5 Replies

7. UNIX for Dummies Questions & Answers

Exit out of the Script Command inside a Script

I'm new to Linux. I have a bash script that invokes an executable. I'd like use the SCRIPT command inside the script and exit out of the script command after it writes to the file. Does this make sense? Below is an example of the contents of my script. #BEGIN SCRIPT script typescript... (6 Replies)
Discussion started by: jmungai
6 Replies

8. Shell Programming and Scripting

Script exit

HI, I written a shell script to stop my peoplesoft applications.Peoplesoft provides a psadmin utility to stop the application. I used the force shutdown option with it psadmin -c shutdown! -d pskri. When my application process hungs in the background the script is not able to continue and... (3 Replies)
Discussion started by: Krrishv
3 Replies

9. Shell Programming and Scripting

exit from script

I have a shell script with options, one of which should exit the system (logout), however when I select this option it drops down to shell, is there a command other than exit that will close the session completely ? (1 Reply)
Discussion started by: gefa
1 Replies

10. UNIX for Dummies Questions & Answers

Where can I find a list of exit codes? (Exit code 64)

I'm receiving an exit code 64 in our batch scheduler (BMC product control-m) executing a PERL script on UX-HP. Can you tell me where I can find a list of exit codes and their meaning. I'm assuming the exit code is from the Unix operating system not PERL. (3 Replies)
Discussion started by: jkuchar747
3 Replies
Login or Register to Ask a Question