Solved

Call multiple scripts to run from master script

Posted on 2013-11-14
6
549 Views
Last Modified: 2013-11-14
HI,

Need script to run scripts 1 through 5 in order, would like to have a bash script that will run each of the five scripts I have in the same directory.  I know there are a couple ways to do this, want the best way, here is the small script I have:

#!/bin/bash
for scripts in /home/user/ "./1* ; ./2* ; ./3* ; ./4* ; ./5* ."
do
  $scripts &
done

the numbers are the scripts 1 through 5.

Thanks
0
Comment
Question by:martinpm123
6 Comments
 
LVL 62

Expert Comment

by:gheist
ID: 39648178
calling 5 of them in a row will make same 5 lines you have
maybe you can use "wait" after done so that parent script waits for others to exit?
0
 
LVL 19

Accepted Solution

by:
xterm earned 350 total points
ID: 39648186
I would name them 1.sh, 2.sh, .... n.sh etc.

Then just do

for script in `ls /path/to/scripts/*.sh`;
do
  $script &
done

That way there won't be any danger of attempting to execute other things in that directory and you don't have to keep changing the master script every time you want to add more scripts to the process.
0
 

Author Comment

by:martinpm123
ID: 39648220
Interesting, yes see that will work, im curious if more than one shell script would be run at the same time, putting a wait statement after done also would be helpful.  I just want each script to run one before the other, because some of the scripts have to be run first before the others of they would fail, the one script adds the Linux server to Active Directory, and another does a chown on the user directories after the AD add.  Is there a way I can make sure the scripts run in order?

Thanks
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 62

Assisted Solution

by:gheist
gheist earned 150 total points
ID: 39648241
Yes - write them in order and remove & (think again - maybe you can use wait as checkpoint if come of them can do in parallel)
0
 
LVL 19

Expert Comment

by:xterm
ID: 39648242
Yes, remove the & from the $script command.  The ampersand tells it to launch into the background which means the script will continue to run and launch all the others virtually at the same time.

If you remove that character, then your master script will wait for each script to run and exit.  Keep in mind that if any of the numbered scripts error out or return non-zero output, it will cause your master to exit without finishing all the other scripts.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 39649174
No need for the ls

for script in  /path/to/scripts/*.sh
do
  $script 
done

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. http://www.linuxmint.com. Once you open the link you will see …
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…
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.

685 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