Solved

Call multiple scripts to run from master script

Posted on 2013-11-14
6
542 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 61

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
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 61

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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.

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now