13

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

tripleee
  • 175,061
  • 34
  • 275
  • 318
Selvakumar Ponnusamy
  • 5,363
  • 7
  • 40
  • 78

2 Answers2

15

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.

Community
  • 1
  • 1
Behnam Safari
  • 2,941
  • 6
  • 27
  • 42
  • 2
    You should avoid the redirections, at least until you know what you are doing. Debugging a failure when you have deliberately thrown away all the diagnostics is a nightmare in the making. – tripleee Feb 16 '12 at 06:49
5

Create file1.sh

#! /bin/sh
echo "Hello World"

Create file2.sh

#! /bin/sh
details = `./file1.sh`
echo $details

give execute permission

chmod +x file1.sh
chmod +x file2.sh

Now run your file

./file2.sh

Output

Hello World
Kundan
  • 107
  • 1
  • 4