Parent Script exiting with child script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parent Script exiting with child script
# 1  
Old 10-27-2010
Parent Script exiting with child script

PARENT SCRIPT

Code:
#!/bin/ksh
#
. $HOME/.profile
. /etl/estdm2/DEV/scripts/DM_ENV_VARS.ksh DEV DB

echo "CALLING CHILD SCRIPT"
. /${SCRIPT_DIR}/DM_CHild.ksh -x HRDATA.dat -e $sEnv -d Wait_Time

*****THE PARENT SCRIPT EXITS HERE ********
*****whether the file is found or not*******

RetCode=$?
	if [ "${RetCode}" != "0" ]
  	then
   	echo "File Not Recieved"
   	fi
exit 0

CHILD SCRIPT (DM_CHild.ksh)

Code:
#!/bin/ksh
#
. $HOME/.profile

FUNCTION_POLL_FOR_FILE
{
POLL FOR THE FILE 
}


if [ FILE NOT FOUND ]
THEN 
        echo "FILE NOT FOUND"
	exit 1
ELSE
	echo "FILE FOUND"
	exit 0 
fi

I assume that the exit in child script is causing an exit in parent script. Is there any way to retrun to the parent without exiting the child.

Earlier (when the parent did not exit with child) the child call was

PHP Code:
/${SCRIPT_DIR}/DM_CHild.ksh -x HRDATA.dat -e $sEnv -d Wait_Time 
but due to some Environment Variable issue we are forcing the child script to run in the same shell as parent -

PHP Code:
. /${SCRIPT_DIR}/DM_CHild.ksh -x HRDATA.dat -e $sEnv -d Wait_Time 
I believe this is the cause of the exit. IS it possible?

Please Any suggestion or help is appreciated.

Thanks
Sumeet
# 2  
Old 10-27-2010
I suppose you could use return, instead of exit in the child script:

Code:
if [ ... ]; then
  echo "FILE NOT FOUND"
  return 1
else
  echo "FILE FOUND"
  return 0 
fi

# 3  
Old 10-27-2010
well...

What you are calling a child script is not really a child. The dot command makes the script run in the current shell. So when it exits, its the same as if the exit was in the "parent".

Try setting a variable instead of exiting, then test that variable back in the "parent" instead of testing RetCode.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fail Parent Script if any of the child fails

I have requirement where I need to fail parent if any one of the child process fails. Here is the code snippet for i in 1 2 3 4 5 6 7 8 9 10 do child_script $i & done wait I need to fail my main script if any one of my child process fails (8 Replies)
Discussion started by: gvkumar25
8 Replies

2. Shell Programming and Scripting

How to exit from the parent script while the child is running?

hi, i want to call a child shell script from a parent shell script. the child will be running for 5 mins. normally when the child is running, parent will wait till the child completes. so in the above case parent will be paused for 5 mins. is there a way so that the parents does not wait for 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

Child exiting and not returning to parent script

I am having a parent scripts which reads a file with child scripts name. I need to read one by one child script , execute it and 1. If child script fails send mail to the team with the log file 2. If the child script executes fine then proceed with the next child script execution. #!... (3 Replies)
Discussion started by: nw2unx123
3 Replies

5. Shell Programming and Scripting

Stop child script by stoping parent script

Hi everyone, I have this problem with a script I'm writting. I want to execute a code running in the background several times through a script. I am writting it like that parent_script for a in 1 2 3 4 5 do exec test -n $a done What I want to do is when parent_script is killed,... (0 Replies)
Discussion started by: geovas
0 Replies

6. Shell Programming and Scripting

Script, child kills parent

Hello everyone, I'm trying to write a script, i would like to say the child kills the parent, how would i do that? (2 Replies)
Discussion started by: jessy21
2 Replies

7. Shell Programming and Scripting

How to return control from the child script to the parent one?

I have two shell scripts : A.sh and B.sh A.sh echo "In A" exec B.sh echo "After B" B.sh echo "In B" The output is : In A In B I want the output : In A In B After B (4 Replies)
Discussion started by: suchismitasuchi
4 Replies

8. Shell Programming and Scripting

Parent/child Korn shell script help

I have the following two Korn shell scripts: SHELL1.ksh #!/usr/bin/ksh nohup sas /abc/123/sasprogram1.sas & SHELL2.ksh #!/usr/bin/ksh ./SHELL1.ksh wait nohup sas /abc/123/sasprogram2.sas & My goal is to run SHELL1.ksh within SHELL2.ksh. SHELL1.ksh runs sasprogram1.sas. I would like... (1 Reply)
Discussion started by: sasaliasim
1 Replies

9. Shell Programming and Scripting

exiting a child without stopping the parent

Greets all. This is using bash/sh on Slackware Linux 12.... I have a parent and MANY children scripts. The parent would be: for script in scripts/*.sh; do sh $script || exit 1 done I'm trying to get a child script to quit running without bombing my parent script. This would be the... (5 Replies)
Discussion started by: madpenguin
5 Replies

10. Shell Programming and Scripting

return valuse from child script to parent script

Hi, I am trying to return a value from child script to a parent script just as a function does. The child script will look for a file and if exists will return 1 else 0. I need to capture the status 1 from child script in the parent script and proceed further. if 0, i need not do... (1 Reply)
Discussion started by: borncrazy
1 Replies
Login or Register to Ask a Question