shankshank
asked on
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
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?
/home/users/this
wait
cp . /home
so it won't run the cp command until the /home/users/this file is done executing?
That is correct
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.
A simple:
/home/users/this
cp . /home
should be all you need.
ASKER