- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Correct exit status
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
тАО05-27-2008 08:26 PM
тАО05-27-2008 08:26 PM
Could you please tell me , what command could I give -IF on some validation in c.sh I want to quit the execution completely. which means, the program must not execute further commands of any parent scripts also.
Please advice.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-27-2008 09:06 PM
тАО05-27-2008 09:06 PM
Solution"calling" another. If one script executes
another script in a subprocess, then, when
the subprocess exits, the first script
normally continues (although it could check
the exit status of the subprocess, and act
accordingly). For example:
td176> cat a1.sh
#!/bin/sh
echo 'Before.'
./b.sh
echo "After, status = $?."
td176> cat b.sh
#!/bin/sh
exit 1
td176> ./a1.sh
Before.
After, status = 1.
td176>
If one script includes (or "sources") the
second script as a script fragment, then any
"exit" in the script fragment is as good as
an "exit" in the first script. For example:
td176> cat a2.sh
#!/bin/sh
echo 'Before.'
. ./b.sh
echo "After, status = $?."
td176> ./a2.sh
Before.
td176>
This example runs the second script, but
tests its exit status:
td176> cat a3.sh
#!/bin/sh
echo 'Before.'
./b.sh
status=$?
if [ $status != 0 ]; then
exit $status
fi
echo "After, status = $?."
td176> ./a3.sh
Before.
td176>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-27-2008 09:07 PM
тАО05-27-2008 09:07 PM
Re: Correct exit status
The way to acheive what you require will be-
1. Write the whole program in one script
2. Validate the return code of c.sh in b.sh and then validate the return code of b.sh in a.sh and exit the program.
Did i make sence or confuse you
Cheers
Raj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-27-2008 09:11 PM
тАО05-27-2008 09:11 PM
Re: Correct exit status
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-27-2008 09:26 PM
тАО05-27-2008 09:26 PM
Re: Correct exit status
IPASMK2.Nightly(main parent shell):
$BIN1/IPASMK2.Copy -n pre-eod
$BIN1/IPASMK2.EOD
$BIN1/IPASMK2.Copy post-eod
$BIN1/IPASMK2.Copy:
$DLC/bin/probkup ipas $BACKUPPATH/ipasii.bkp -com >> $LOG
if [ $? -gt 0 ]
then
exit 1
fi
After Modification IPASMK2.Nightly:
$BIN1/IPASMK2.Copy -n pre-eod
if $?=1
then
exit 1
fi
$BIN1/IPASMK2.EOD
$BIN1/IPASMK2.Copy post-eod
if $?=1
then
exit 1
fi
Is it looking Okay now?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-27-2008 10:04 PM
тАО05-27-2008 10:04 PM
Re: Correct exit status
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-27-2008 11:10 PM
тАО05-27-2008 11:10 PM
Re: Correct exit status
> then
> exit 1
> fi
Is "1" the only possible bad status value
from the script? Is "1" the only bad status
value you wish to return?
> status=$?
> if [ $status != 0 ]; then
> exit $status
> fi
This is longer and more complicated, but it
also stops on any non-zero status value, and
it returns that status value to the user, who
may care what it is.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-28-2008 01:30 AM
тАО05-28-2008 01:30 AM
Re: Correct exit status
This isn't valid syntax. The correct syntax is:
if [ $? -eq 1 ]; then
>Steven:
> if [ $status != 0 ]; then
While this may work, this is doing a string compare and not an integer compare. Instead do:
if [ $status -ne 0 ]; then
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-28-2008 05:51 PM
тАО05-28-2008 05:51 PM
Re: Correct exit status
Good point. (My shell script skills must be
oxidizing, like all my other skills.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-28-2008 06:16 PM
тАО05-28-2008 06:16 PM
Re: Correct exit status
oxidizing
You can of course go crazy and use C style expressions in a real shell:
if (( status != 0 )); then