Child exiting and not returning to parent script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Child exiting and not returning to parent script
# 1  
Old 03-18-2013
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.

Code:
#! /bin/ksh
set -x
#**************************************************************************#
# Program Name         : test.ksh
#***************************************************************************#

while read line
do
  
  . /child1.ksh 
  returnstatus=$?
  
  if [ returnstatus -ne 0 ]
  then
                <mail the team>
                if [ $? -ne 0 ]
                then
                        echo "Error while sending the mail"
                        exit 255
                else
                        echo "Mail sent successfully"
         fi
  else
                echo "$line ran successfully"
                <run the next child script>
 fi
                                                                                                                                                              
done <"$file"

exit 0


Code:
The file will be like
child1
child2
child3
child4
child5

# 2  
Old 03-18-2013
You are not running them, you are sourcing them. I'm assuming this sourced script uses $line, otherwise your program does nothing..

Code:
if [ "$returnstatus" -ne 0 ]


Last edited by Corona688; 03-18-2013 at 03:19 PM..
# 3  
Old 03-18-2013
I just removed the . from . /child1.ksh
and it worked fine.


The $line is nothing but the following line by line from the file
child1
child2
child3
child4
child5
# 4  
Old 03-18-2013
Quote:
Originally Posted by nw2unx123
I just removed the . from . /child1.ksh
and it worked fine.
Good. I wasn't sure if that was intentional, since that's a valid way to run a script in your own shell.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Control from UNIX script is not returning to the Parent program

Hi All, My program flow is as below Windows batch -- > Cygwin batch --> zsh script There are multiple Cygwin batch scripts that are called from Windows batch file . But when i am executing the first cygwin batch script the control goes to the zsh file and executes and stoping from... (1 Reply)
Discussion started by: Hypesslearner
1 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

forking a child process and kill its parent to show that child process has init() as its parent

Hi everyone i am very new to linux , working on bash shell. I am trying to solve the given problem 1. Create a process and then create children using fork 2. Check the Status of the application for successful running. 3. Kill all the process(threads) except parent and first child... (2 Replies)
Discussion started by: vizz_k
2 Replies

4. Shell Programming and Scripting

Script returning an error message on exiting

Hi, I am writing a script in which I am using an IF-Else statement. Code sample: # Check for the product. If (test "$3" = "Pet") Then Product_Code="PI" elif (test "$3" = "Breakdown") Then Product_Code="RI" elif (test "$3" = "Travel") Then Product_Code="TI" ... (2 Replies)
Discussion started by: bghosh
2 Replies

5. Shell Programming and Scripting

Parent Script exiting with child script

PARENT SCRIPT #!/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******* ... (2 Replies)
Discussion started by: sumeet
2 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

Returning values from child to parent shell

I need to send the status from child shell failure to parent shell. I would like to know how could we accomplish this. My parent.sh is as below: #!/bin/ksh set -x echo "I am in parent shell now..." child.sh ret_stat=$? echo "rest_stat=$ret_stat" echo "I am below parent shell end..." ... (4 Replies)
Discussion started by: acheepi
4 Replies
Login or Register to Ask a Question