Run 2 shell scripts simultaneously from one script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run 2 shell scripts simultaneously from one script
# 1  
Old 02-18-2015
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
# 2  
Old 02-18-2015
Any attempts from your side?
# 3  
Old 02-18-2015
I make "Mod_new.sh" file like this .....

Code:
#!/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)

Last edited by Scrutinizer; 02-18-2015 at 02:41 PM.. Reason: icode tags to code tags
# 4  
Old 02-18-2015
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 bashis available loses many of the advanced features that bash provides.
# 5  
Old 02-18-2015
Code:
#!/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
# 6  
Old 02-19-2015
Create new file Mod_new.sh
Code:
#!/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......
Code:
[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

.

Last edited by Scrutinizer; 02-19-2015 at 07:02 AM.. Reason: icode tags -> code tags ; no tags -> code tags
# 7  
Old 02-19-2015
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:
Code:
if [ -x "$mS" ] ; then
    ./$mS "$1" & 
else
    $SHELL $mS "$1" &
fi

hth
This User Gave Thanks to sea For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run scripts parallely inside shell script?

Hi , I have 4 scripts example script1,script2,script3,script4 . I have to run script1,script2 and script3 parallely since this 3 scripts dont have dependencies . Once script1,script2 and script3 got completed successfully , I have to trigger script4. Can someone help me on this how to... (10 Replies)
Discussion started by: vinothsekark
10 Replies

2. Shell Programming and Scripting

Shell script for running simultaneously two interfaces

Hi! I have two environments on a machine and each one has some scripts for checking if some interfaces are down, and if so, it restarts them. The issue now is that i cannot keep both interfaces running, on both environments i see the same process running. How can i modify my scripts in... (4 Replies)
Discussion started by: Jane_Doe
4 Replies

3. Shell Programming and Scripting

Shell script to run all the python scripts from particular directory

I have N number of python scripts which i am receiving from REST web server and i am saving them in /home/mandar/ . Now i want to write a script to run all the python scripts from this directory and monitor them every minute...if any process is dead or hung it should be restarted by this script. ... (0 Replies)
Discussion started by: Mandar Nandale
0 Replies

4. Shell Programming and Scripting

Behavior of Unix in calling 2 scripts simultaneously

Hi, I wanted to know the exact behavior of the shell scripts in the below scenario. I have 2 scripts - a.ksh and b.ksh Both these scripts call a 3rd script xyz.ksh. What will happen if both a.ksh and b.ksh run at the same time? What will happen if a.ksh starts 2-3 seconds before b.ksh?... (3 Replies)
Discussion started by: aster007
3 Replies

5. Shell Programming and Scripting

[Help] script how to run 2 commands simultaneously

#!/bin/sh firefox index.html firefox secondpage.html hey guys, im not able to open up two pages at the same time... it always open up index.html first, and only after i close it, then the 2nd page pops up... is there any way i can run both commands at the same time? i appreciate any... (2 Replies)
Discussion started by: funnyguy123
2 Replies

6. Shell Programming and Scripting

To call many scripts from mother one simultaneously

Hi, I need to rin few other scripts from one main (mather) script. Working in ksh on LINUX. The only one condition - it should be run in parallel. I mean I have to be able to call 20 scripts from this mother script in parallel (start them in the same time). Does somebody know how to do it? ... (2 Replies)
Discussion started by: juliyp
2 Replies

7. Shell Programming and Scripting

Run a command in bg simultaneously with

Hi, I want to run the command below in the background: tail -f file.txt | grep "pattern" The file file.txt will start getting its contents written after this command has started getting run. So the flow will be like this tail -f file.txt | grep "pattern" #The line below will write data... (0 Replies)
Discussion started by: King Nothing
0 Replies

8. Shell Programming and Scripting

run serveral loops simultaneously?

Hello everyone, say I have the following script, which contains serveral loops, if I run the script, it executes the loop one by one (after the a loop, it goes to b loop, then c, then d) I figured I should be able to run all the loops at same time, but I don't know how, can anyone help a little... (2 Replies)
Discussion started by: fedora
2 Replies

9. Shell Programming and Scripting

sequentially run the shell scripts.

Hi All, I have a master script , which would run 4 scripts in sequence. When the first script gets executed , I need to check if a particular process has been completed. If it is completed , only then proceed with the second script. This same rule applies to script3 and script4. Can someone... (4 Replies)
Discussion started by: nua7
4 Replies

10. Linux

Possible ways to run shell scripts on Windows

Hi all, I want to know possible ways to exceute the shell scripts on Windows environment. Please help me. Regards, Uday. (2 Replies)
Discussion started by: uday123
2 Replies
Login or Register to Ask a Question