Solved

Unix script wait to complete

Posted on 2010-09-02
6
410 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
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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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

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…
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…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.:

828 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