Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run sh file from another sh file

Tags:

linux

shell

unix

sh

I have a shell script file for monitoring my application, this script will be executed every 10 min by setting cron job.

I would like to some more script files which are related to monitoring should be executed along with master file. So I would like to include my scripts to master file. How to run those sh file from master sh file

like image 832
Selvakumar Ponnusamy Avatar asked Feb 16 '12 04:02

Selvakumar Ponnusamy


People also ask

How run sh from another directory?

To use full path you type sh /home/user/scripts/someScript . sh /path/to/file is different from /path/to/file . sh runs /bin/sh which is symlinked to /bin/dash . Just making something clear on the examples you see on the net, normally you see sh ./somescript which can also be typed as `sh /path/to/script/scriptitself'.

Can CMD run sh files?

Open Command Prompt and navigate to the folder where the script file is available. Type Bash script-filename.sh and hit the enter key. It will execute the script, and depending on the file, you should see an output.


1 Answers

Take a look at this. If you want to run a script you can use:

./yourscript.sh

If your script has a loop, use:

./yourscript.sh&

If you want to get the console after starting scripts and you don't want to see it's output use:

./yourscript.sh > /dev/null 2>&1 &

So, in the master file you'll have:

./yourscript1.sh > /dev/null 2>&1 &
./yourscript2.sh > /dev/null 2>&1 &
./yourscript3.sh > /dev/null 2>&1 &

They will start together.

like image 79
Behnam Safari Avatar answered Oct 21 '22 13:10

Behnam Safari