Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 433
  • Last Modified:

Unix script wait to complete

If i have a cron job that runs a file, say called run.

and in run we have some commands, including another file to run, specified by say

/home/users/this.sh

The file this.sh is run but the original file run continues to other commands without waiting for this.sh to complete, right?

0
shankshank
Asked:
shankshank
  • 3
  • 2
1 Solution
 
bobalobCommented:
There are wait and waitpid commands that will wait for child processes to terminate before continuing.

http://linux.about.com/od/commands/l/blcmdl2_wait.htm
0
 
shankshankAuthor Commented:
so how would i utilize that in this script
0
 
bobalobCommented:
Literally you can insert the wait command after the command you wish to wait for. For example...

There is an example on the Wikipedia page for the command...

http://en.wikipedia.org/wiki/Wait_%28command%29

#!/bin/bash
 
# Parallel update script which makes use of the wait command
 
# Update local copy
rsync iona:src/ . &
# Upgrade required libraries, or exit indicating failure if make failed for some reason
make -C lib || exit 1
 
# Wait for rsync to terminate (may have already happened) and finish the job, unless rsync failed
wait && make

There are plenty of examples on the internet, it is very easy to use.
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
shankshankAuthor Commented:
so i can do this in my run
/home/users/this
wait
cp . /home

so it won't run the cp command until the /home/users/this file is done executing?
0
 
bobalobCommented:
That is correct
0
 
TintinCommented:
Unless there is something highly unusual with your script, there is absolutely no need for using 'wait' as you aren't putting the script in the background.

A simple:

/home/users/this
cp . /home

should be all you need.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now