Solved

Unix script wait to complete

Posted on 2010-09-02
6
419 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

717 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