LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   i am running 2 scripts in background if 1 exits with error the other should also exit (https://www.linuxquestions.org/questions/programming-9/i-am-running-2-scripts-in-background-if-1-exits-with-error-the-other-should-also-exit-684870/)

pradyumna_reddy 11-20-2008 07:57 AM

i am running 2 scripts in background if 1 exits with error the other should also exit
 
Hello,

i am running a Script main.sh which runs 2 scripts in background if one script exits with error another script should also exit.

this is how the scripts look like

Main.sh


#!/bin/bash

cd $YVIEW/

date >ybuild_cmn.log

ybuild -cmn >>ybuild_cmn.log ; [ $? -ne 0 ] && exit 0



$HOME/file1.sh &
if [ $? -ne 0 ] ; then
exit
fi

$HOME/file2.sh & [ $? -ne 0 ] && exit 0
if [ $? -ne 0 ] ; then
exit
fi

file1.sh

#!/bin/bash

echo running file1

echo iew variable = $YVIEW

echo iew name $YVIEWNAME

cd $YVIEW/nemsw/

ybuild -b bam83xx -mr boot >bam83.log ; [ $? -ne 0 ] && exit 1

ybuild -b bam83xx -mr shared >bam83_sha.log ; [ $? -ne 0 ] && exit 1

ybuild -b bam83xx -mr iomod >bam83_io.log ; [ $? -ne 0 ] && exit 1

ybuild -b bam405ex -mr shared >bam83_ex.log ; [ $? -ne 0 ] && exit 1

ybuild -b bam83xx -mr ctrlr >bam83_ctrl.log ; [ $? -ne 0 ] && exit 1

ybuild -b bam405h -mr shctrlr >bam405h_shctrlr.log ; [ $? -ne 0 ] && exit 1

ybuild -b man8541 -mr ndctrlr >bam4054_ndctrlr.log ; [ $? -ne 0 ] && exit 1

exit 0

file2.sh



#!/bin/bash

echo running file2

echo view variable = $YVIEW

echo view name $YVIEWNAME

cd $YVIEW/nemsw/

ybuild -b bam405h -mr boot >bam405h.log ; [ $? -ne 0 ] && exit 1

ybuild -b bam405h -mr shared >bam405h_shared.log ; [ $? -ne 0 ] && exit 1

ybuild -b bam405h -mr iomod >bam405h_iomod.log ; [ $? -ne 0 ] && exit 1

ybuild -b bam405h -mr ctrlr >bam405h_ctrlr.log ; [ $? -ne 0 ] && exit 1

ybuild -b man8541 -mr boot >man8541_bo.log ; [ $? -ne 0 ] && exit 1

ybuild -b man8541 -mr shared >man8541_sh.log ; [ $? -ne 0 ] && exit 1

ybuild -b man8541 -mr shctrlr >man8541_shctrlr.log ; [ $? -ne 0 ] && exit 1

exit 0

but my code is not working as desired ,if any error on in file.sh is not exiting file2.sh also ,in fact it should exit the whole script.

please help me on this

colucix 11-20-2008 09:05 AM

Please, don't post the same thread in multiple forums! Reported.

crabboy 11-24-2008 01:42 PM

closing thread. Duplicate in General


All times are GMT -5. The time now is 04:35 PM.