LinuxQuestions.org
Register a domain and help support LQ
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



Reply
 
Search this Thread
Old 01-22-2008, 02:26 PM   #1
ArthurHuang
Member
 
Registered: Jan 2006
Posts: 174

Rep: Reputation: 30
Bash script programming problem


I have the following items in the example.sh file

./function1
./function2
./manualFunction3
./function4

functionX will automatically run, however, manualFunction3 need some people's coorporation and time is not predictable, which means I can't use sleep to wait for its completion.

So my question is, when I have finished ./manualFunction3, how does the scripts knows and continues to run function4?

Thanks!
 
Old 01-22-2008, 02:42 PM   #2
stlouis
Member
 
Registered: Jul 2006
Location: Sault Ste. Marie, Ontario
Distribution: RedHat, CentOS, Fedora Core, Gentoo, Slackware
Posts: 63

Rep: Reputation: 15
Is Function4 dependent on manualFunction3?

If so, why NOT have manualFunction3 call Function4 when it completes everything else?


Are you currently having problems with your script? Normally, functions in a script are executed one at a time, each waiting for the previous function to complete before starting...

The way you have your's set though, looks like you are essentially spawning sub-process, which if so, you really have no control over, because once started, they are their own process...


What exactly is your script trying to accomplish?
 
Old 01-22-2008, 02:50 PM   #3
Hobbletoe
Member
 
Registered: Sep 2004
Location: Dayton, Oh
Distribution: Linux Mint 10, Linux Mint 11
Posts: 148

Rep: Reputation: 18
Code:
./malFunction3 && ./function4
This will run ./function4 after ./malFunction3 is completely successfully. Is this what you need?
 
Old 01-22-2008, 03:46 PM   #4
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by ArthurHuang View Post
So my question is, when I have finished ./manualFunction3, how does the scripts knows and continues to run function4?
This kind of thing is usually solved using this kind of construct:
Code:
./function1
./function2
if ! ./manualFunction3 ; then
    exit 1;
fi
./function4
Just make sure your "manualFunction3" returns a non-zero value on failure.
 
Old 01-23-2008, 04:22 PM   #5
ArthurHuang
Member
 
Registered: Jan 2006
Posts: 174

Original Poster
Rep: Reputation: 30
Let me have try this one
Thanks!
Quote:
Originally Posted by Hobbletoe View Post
Code:
./malFunction3 && ./function4
This will run ./function4 after ./malFunction3 is completely successfully. Is this what you need?
 
Old 01-23-2008, 04:24 PM   #6
ArthurHuang
Member
 
Registered: Jan 2006
Posts: 174

Original Poster
Rep: Reputation: 30
I can't because I can't edit and recompile manualFunction3.

And they are independent two functions and can't be called.

Thanks!
Quote:
Originally Posted by stlouis View Post
Is Function4 dependent on manualFunction3?

If so, why NOT have manualFunction3 call Function4 when it completes everything else?


Are you currently having problems with your script? Normally, functions in a script are executed one at a time, each waiting for the previous function to complete before starting...

The way you have your's set though, looks like you are essentially spawning sub-process, which if so, you really have no control over, because once started, they are their own process...


What exactly is your script trying to accomplish?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
issues programming a script in BASH gravesb Linux - Software 1 07-07-2005 02:03 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 01:20 AM
Bash script programming questions dianea Linux - Newbie 4 03-03-2004 01:17 AM


All times are GMT -5. The time now is 10:59 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration