HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Getting pid and return code of the called script w...
Operating System - HP-UX
1827452
Members
3767
Online
109965
Solutions
Forums
Categories
Company
Local Language
back
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
Discussions
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
04-20-2005 11:56 PM
04-20-2005 11:56 PM
Greetings,
I am writing a shell script in which I need to call another shell script.
However I need to check the pid and the return code of the called script.
I should look like as:
$WORKING_DIRECTORY/script.sh &
pid=$!
wait
ReturnCode=$?
...
My problem is that I am not able to get in ReturnCode the exit code of script.sh?
Any help/suggestion is highly appreciated.
Thanks in advance for your help,
Kind Regards,
Rui Vilao.
I am writing a shell script in which I need to call another shell script.
However I need to check the pid and the return code of the called script.
I should look like as:
$WORKING_DIRECTORY/script.sh &
pid=$!
wait
ReturnCode=$?
...
My problem is that I am not able to get in ReturnCode the exit code of script.sh?
Any help/suggestion is highly appreciated.
Thanks in advance for your help,
Kind Regards,
Rui Vilao.
"We should never stop learning"_________ rui.vilao@rocketmail.com
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2005 12:15 AM
04-21-2005 12:15 AM
Re: Getting pid and return code of the called script within script
Hi Rui,
I created a same construction, only with functions.
In the function called in the background, I fill the variable PROG, which I monitor in the function below.
TIMEOUT=10
MAX_TIMEOUT=3600 #one hour
# Monitor the proces
while (( $(UNIX95= ps -xC $(basename ${PROG}) |grep ${ORACLE_SID} |wc -w) > 0 ))
do
# wait for the timeout period
sleep ${TIMEOUT}
# update counter with one
(( counter +=1 ))
# calculate total waiting time
(( wait_time=${counter}*${TIMEOUT} ))
# Show feedback as a dot every timeout time
printf "."
if (( ${wait_time} > ${MAX_TIMEOUT} ))
then
print "Killing ${ORACLE_SID} backup process after ${wait_time} seconds"
kill ${backup_process}
fi
done
Another possibility is to use the command jobs, i.e. :
while (( $(jobs | wc -l) > 0 ))
do
# wait for the timeout period
sleep ${TIMEOUT}
# update counter with one
(( counter +=1 ))
# calculate total waiting time
(( wait_time=${counter}*${TIMEOUT} ))
done
Hope it helps,
Renarios
I created a same construction, only with functions.
In the function called in the background, I fill the variable PROG, which I monitor in the function below.
TIMEOUT=10
MAX_TIMEOUT=3600 #one hour
# Monitor the proces
while (( $(UNIX95= ps -xC $(basename ${PROG}) |grep ${ORACLE_SID} |wc -w) > 0 ))
do
# wait for the timeout period
sleep ${TIMEOUT}
# update counter with one
(( counter +=1 ))
# calculate total waiting time
(( wait_time=${counter}*${TIMEOUT} ))
# Show feedback as a dot every timeout time
printf "."
if (( ${wait_time} > ${MAX_TIMEOUT} ))
then
print "Killing ${ORACLE_SID} backup process after ${wait_time} seconds"
kill ${backup_process}
fi
done
Another possibility is to use the command jobs, i.e. :
while (( $(jobs | wc -l) > 0 ))
do
# wait for the timeout period
sleep ${TIMEOUT}
# update counter with one
(( counter +=1 ))
# calculate total waiting time
(( wait_time=${counter}*${TIMEOUT} ))
done
Hope it helps,
Renarios
Nothing is more successfull as failure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2005 12:21 AM
04-21-2005 12:21 AM
Solution
Rui,
First off, to be careful you should do this:
$WORKING_DIRECTORY/script.sh &
pid=$!
wait $pid
ReturnCode=$?
IIRC, one of the problems with the wait command is that it only returns the RC of the child process if it is executed *before* the script exits. Given the way UNIX functions, this will not necessarily be the case - (if script.sh exits very quickly for instance). \
In these situations I've always had my child processes write their status to a temp file which I can the read from the parent process - a kludge I know, but much more likely to work.
HTH
Duncan
I am an HPE Employee
First off, to be careful you should do this:
$WORKING_DIRECTORY/script.sh &
pid=$!
wait $pid
ReturnCode=$?
IIRC, one of the problems with the wait command is that it only returns the RC of the child process if it is executed *before* the script exits. Given the way UNIX functions, this will not necessarily be the case - (if script.sh exits very quickly for instance). \
In these situations I've always had my child processes write their status to a temp file which I can the read from the parent process - a kludge I know, but much more likely to work.
HTH
Duncan
I am an HPE Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2005 01:07 AM
04-21-2005 01:07 AM
Re: Getting pid and return code of the called script within script
Prblem solved thanks to Duncan & Renarios!
Cheers,
Rui.
"We should never stop learning"_________ rui.vilao@rocketmail.com
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP