?
Solved

Call multiple scripts to run from master script

Posted on 2013-11-14
6
Medium Priority
?
554 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 1400 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 62

Assisted Solution

by:gheist
gheist earned 600 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Fine Tune your automatic Updates for Ubuntu / Debian
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
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
Course of the Month7 days, 19 hours left to enroll

765 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