LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Closed Thread
  Search this Thread
Old 11-20-2008, 07:57 AM   #1
pradyumna_reddy
LQ Newbie
 
Registered: Nov 2008
Location: Hyderabad
Posts: 2

Rep: Reputation: 0
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
 
Old 11-20-2008, 09:05 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Please, don't post the same thread in multiple forums! Reported.
 
Old 11-24-2008, 01:42 PM   #3
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
closing thread. Duplicate in General
 
  


Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
running 2 scripts in background ,if any 1 exits with error the other 1 also exit pradyumna_reddy Linux - General 2 11-20-2008 01:54 PM
Log what exits in bash script. What causes exit code thats not 0? Trailsmoke Programming 2 09-25-2008 03:07 AM
How to exit and save (or just to exit) inside a "make config" running command? scrat75 Linux - Kernel 6 09-05-2008 04:02 PM
getting the exit status of a background processes gururaj Linux - General 7 04-27-2006 05:56 PM
Bash - background process and exit ?? michael_util Programming 4 01-05-2005 11:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration