Solved

Call multiple scripts to run from master script

Posted on 2013-11-14
6
538 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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…
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…
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.

760 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

18 Experts available now in Live!

Get 1:1 Help Now