Solved

Unix script wait to complete

Posted on 2010-09-02
6
417 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
bobalob earned 500 total points
ID: 33587186
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
ID: 33587193
so how would i utilize that in this script
0
 
LVL 3

Expert Comment

by:bobalob
ID: 33587255
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 5

Author Comment

by:shankshank
ID: 33587273
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
ID: 33587299
That is correct
0
 
LVL 48

Expert Comment

by:Tintin
ID: 33602269
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses

738 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