Solved

Call multiple scripts to run from master script

Posted on 2013-11-14
6
550 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
[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
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
Technology Partners: 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!

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
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.
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.
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