- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Easy shell script (korn) question
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-29-2001 12:30 AM
тАО07-29-2001 12:30 AM
I know I can put an & at the end of the first command so the second one kicks off right away and runs at the same time, but how do I make the shell script wait for the next command if the second one finishes first?
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-29-2001 02:21 AM
тАО07-29-2001 02:21 AM
Re: Easy shell script (korn) question
Use wait command. wait command will wait untill the previous background command finishes. See the man page for more info.
Reg,
Paulson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-29-2001 04:37 AM
тАО07-29-2001 04:37 AM
Re: Easy shell script (korn) question
Consider this:
./mytask1 &
T1=$! #...capture the pid of mytask1...
./mytask2
if [ $? -eq 0 ]; then
echo "task2 completedok"
fi
wait T1 #...wait for mytask1...
if [ $? -eq 0 ]; then
echo "task1 completedok"
fi
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-29-2001 11:50 AM
тАО07-29-2001 11:50 AM
SolutionBy far the easist method is you don't care about the order of execution is:
cmd1.sh &
cmd2.sh &
wait
wait will then pause the parent shell until all child processes have completed.
A variation on this is:
(cmd1.sh; cmd2.sh) &
cmd3.sh
wait
In this case cmd2.sh does not start until cmd1.sh has finished. cmd3.sh run concurrently with cmd1.sh,cmd2.sh. Control does not return until all child processes have finished.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-29-2001 11:51 AM
тАО07-29-2001 11:51 AM
Re: Easy shell script (korn) question
By far the easist method is you don't care about the order of execution is:
cmd1.sh &
cmd2.sh &
wait
wait will then pause the parent shell until all child processes have completed.
A variation on this is:
(cmd1.sh; cmd2.sh) &
cmd3.sh &
# I missed this ampersand in the prior posting
wait
In this case cmd2.sh does not start until cmd1.sh has finished. cmd3.sh run concurrently with cmd1.sh,cmd2.sh. Control does not return until all child processes have finished.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-30-2001 03:37 AM
тАО07-30-2001 03:37 AM
Re: Easy shell script (korn) question
example :
cmd1 &
cmd2 &
wait
cmd3
cmd3 will execute only and only if cmd1 AND cmd2 finish ( both of then )
Note : wait is a synchronizing point.
Magdi