- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Exit commands not working in shell script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2001 03:40 AM
тАО10-09-2001 03:40 AM
Exit commands not working in shell script
I writing a POSIX shell script on HPUX 11.0 that I intend to have exit at various points with different error codes and the exit statements are not working (they are just being ignored and the script is continuing to execute). A smaller, simpler script containing exit codes does work when executed manually. The script will normally be cronned, but I'm pretty sure that the problem occurs when being run manually (it is difficult to test since it contains LVM and XP commands). Surely this can be done?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2001 03:46 AM
тАО10-09-2001 03:46 AM
Re: Exit commands not working in shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2001 03:54 AM
тАО10-09-2001 03:54 AM
Re: Exit commands not working in shell script
xpinfo | grep HP
echo $?
Then you'll have the exit code for the grep not the xpinfo command.
Seperate your commands if you want to get error codes.
Later,
Bill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2001 04:51 AM
тАО10-09-2001 04:51 AM
Re: Exit commands not working in shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2001 04:58 AM
тАО10-09-2001 04:58 AM
Re: Exit commands not working in shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2001 04:59 AM
тАО10-09-2001 04:59 AM
Re: Exit commands not working in shell script
You are probably not executing what you think you are executing. I suggest adding 'set -x' to your script or running it with this option to print commands and their arguments as they are processed:
# sh -x ./my.sh
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2001 05:05 AM
тАО10-09-2001 05:05 AM
Re: Exit commands not working in shell script
So, and exit will not break your sh, just the new sh automaticaly generated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2001 06:08 AM
тАО10-09-2001 06:08 AM
Re: Exit commands not working in shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2001 07:08 AM
тАО10-09-2001 07:08 AM
Re: Exit commands not working in shell script
I agree with you, your script looks sound. I cut out the section that did the mount test and it worked correctly. I'm wondering if it is something in your environment, but I can't imagine what that would be.
Do you have this posix (sh) patch installed?
ftp://ftp.itrc.hp.com/hp-ux_patches/s700_800/11.X/PHCO_23873
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2001 07:35 AM
тАО10-09-2001 07:35 AM
Re: Exit commands not working in shell script
That's an interesting puzzle. There's got to be a logical explaination. I took you attachment, commented out most things, and the exit worked fine. I'd try some things such as:
Try adding an exit just before: if [ "$DIRCNT" -ne 3 ]
Try swapping the exit and echo lines (just for grins).
Put an echo and exit just after the fi ending your DIRCNT -ne 3 logic.
Check the log file again. Perhaps there's a clue hidden in it. I find it hard to believe exit is being ignored if actually seen by the shell.
When you solve this there's a bunch of people who'd like to know the answer! Please post it. Thanks,
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2001 07:38 AM
тАО10-09-2001 07:38 AM
Re: Exit commands not working in shell script
There are a few POSIX sh patches that deal with exit although I didn't find any that fit yours precisely. I would install the latest cumulative patch PHCO_23873.
The other thing I would do is put an echo after your exit in question. That way you know for sure if the problem is somehow related to loops, functions, child-processes, etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2001 07:52 AM
тАО10-09-2001 07:52 AM
Re: Exit commands not working in shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2001 08:20 AM
тАО10-09-2001 08:20 AM
Re: Exit commands not working in shell script
I simply cannot reproduce this. I even tried some very creative uses of the trap cmd 0 statement to try to cause the exit to be ignored. I thought I saw one construct which could cause problems. Your echo "something "$XX" something else" which really outght to have the enclosed quotes escaped -> echo "something \"${XX}\" something else" - but that didn't do anything fix it.
My next suggestion is twofold.
1) Put an echo "Set: ${-}" statement in so that you can see any options set.
2) Put some probes in very early in your code with an exit statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2001 08:25 AM
тАО10-09-2001 08:25 AM
Re: Exit commands not working in shell script
I do believe your problem stems from the use
of "ls ...|wc -l" in your script. If you do
this interactively, then "ls" does behave
differently than in scripts! Try using the
option "-1" (read: dash one) for the "ls",
then try again - and this time start your
script with "sh -v -x yourscript"...
Then you will see the command BEFORE and AFTER
the shell does the substitution.
BTW, if you insert something like
exec 2>&1 > $LOG
as one of the first lines in your script, then
you do not need all those ">> $log" in all the
lines :-)
Good luck,
Wodisch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2001 08:28 AM
тАО10-09-2001 08:28 AM
Re: Exit commands not working in shell script
In looking at the logs and the script you submitted, I see that when the DIRCNT is NOT EQUAL to 3, this should exit. But in the log I see that the DIRCNT was equal to three by the line :
Only 3 filesystems mounted
Not sure if this will trigger something for someone, but its looks to me as though the DIRCNT was equal to 3, but the script tried to exit anyway...
Anyone?
-Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2001 08:41 AM
тАО10-09-2001 08:41 AM