Run 2 shell scripts simultaneously from one script

i Run 2 scripts on all of around 50 nodes every day.

1.Mod_1.sh
2.Mod_2.sh

eg..
i run file with specific node no like

Mod_1.sh NODE_(node number)
Mod_2.sh NODE_(node number)

I want to run both file by using single script with unique node number.

Eg..
Mod_new.sh NODE_(node number) ================>this file run both Mod_1.sh and Mod_2.sh with unique node number plz help

Any attempts from your side?

I make "Mod_new.sh" file like this .....

#!/bin/bash
#This is script for NODE Post configuration
#echo "Running script for $1"
sh -x Mod_1.sh
sh -x Mod_2.sh

(But how to give single same input number to both file)

PLease use code tags as required by forum rules!

I'm not sure I understand. What keeps you from supplying the node info to Mod_1 and _2 ?
BTW - running those with sh when bash is available loses many of the advanced features that bash provides.

#!/usr/bin/env bash
for mS in myScriptA.sh myScriptB.sh
do
    [ -x "$mS" ] && \
        ./$mS "$1" & || \
        $SHELL $mS "$1" &
done

This checks myScriptA and myScriptB wether the files have execution flag or not.
If it has, just start the script, if it hasent, use its very own $SHELL to start it.
Oh yeah, and pass the first argument passed those scripts too and sends them to background so they run simultaniously.

hth

Create new file Mod_new.sh

#!/usr/bin/env bash
for mS in Mod_1.sh Mod_2.sh
do
    [ -x "$mS" ] && \
        ./$mS "$1" & || \
        $SHELL $mS "$1" &
done

Getting following error......

[KTTM:/home/view/bin] Mod_new.sh NODE_5  ======>i have to run file like this
./Mod_new.sh: line 6: syntax error near unexpected token `||'
./Mod_new.sh: line 6: `        ./$mS "$1" & || \'

plz help

.

Please use CODE tags, the icon with the text 'code' on it.
The iCodes are nice to provide a sample code without the need of line break, not applicable for script or debug output!

Any luck making brackets ./$mS "$1" & so it looks like: (./$mS "$1" &) ?

If not, rewrite that block to:

if [ -x "$mS" ] ; then
    ./$mS "$1" & 
else
    $SHELL $mS "$1" &
fi

hth

1 Like

Thanku
But not working...

Now i running sh file like..

[KTTM:/home/view/bin] Mod_1.sh NODE_5
[KTTM:/home/view/bin] Mod_1.sh NODE_5

I want run..

[KTTM:/home/view/bin] Mod_New.sh NODE_5
.
.

In which Mod_New.sh will run both Mod_1.sh &Mod_1.sh file with unique input NODE_5

NODE may be..
NODE_5
NODE_6
NODE_7
NODE_8

I want to run both file from same script...

---------- Post updated at 03:40 AM ---------- Previous update was at 03:31 AM ----------

I know very less about SH scripting..........

Please use code tags as required by forum rules!

doesn't help us help you. Please be very specific with error messages.

Does this work if executed IN your script:

Mod_1.sh NODE_5
Mod_2.sh NODE_5

?
Does this work if executed IN your script:

Mod_1.sh $1
Mod_2.sh $1

with NODE_5 supplied to your script as the first parameter?

Does this work if executed IN your script:

Mod_1.sh $1 &
Mod_2.sh $1 &

?

1 Like

its working fineeee

HOW Can we run it for multiple nodes at once
like

Mod_1.sh NODE_5,6,7,8,10,11,55,48

---------- Post updated at 05:19 AM ---------- Previous update was at 01:08 AM ----------

Mod_1.sh NODE_5

for running above command My script is like...

Mod_1.sh $1
Mod_2.sh $1

HOW Can we run it for multiple nodes at once
like

Mod_1.sh NODE_5,6,7,8,10,11,55,48

?
?

Can any one help ??

You do NOT want to name your script Mod_1.sh and have it invoke Mod_1.sh and Mod_2.sh . You are not ready to handle recursive scripts yet.

You could make your script relatively complex and try to parse the single operand you have suggested passing to your script...

Or, assuming that MOD is a constant in all of your calls and does not need to be passed as an operand to your script, you can make it simple on yourself and invoke your script something like this:

Mod_NEW.sh 5 6 7 8 10 11 55 48

with Mod_NEW.sh containing something like:

#!/bin/sh
for node in "$@"
do	Mod_1.sh MOD_"$node"
	Mod_2.sh MOD_"$node"
done

This will work with any shell that accepts basic Bourne shell syntax such as ash , bash , dash , and (my preferred shell) ksh .