Solved

Unix script wait to complete

Posted on 2010-09-02
6
407 Views
Last Modified: 2012-05-10
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
Comment
Question by:shankshank
  • 3
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
bobalob earned 500 total points
Comment Utility
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
 
LVL 5

Author Comment

by:shankshank
Comment Utility
so how would i utilize that in this script
0
 
LVL 3

Expert Comment

by:bobalob
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Author Comment

by:shankshank
Comment Utility
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
 
LVL 3

Expert Comment

by:bobalob
Comment Utility
That is correct
0
 
LVL 48

Expert Comment

by:Tintin
Comment Utility
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

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now