Jithin Jithin - 1 month ago 15
Bash Question

To execute multiple bash scripts in diff directories using one single bash script

I have multiple bash scripts to bounce Jboss instances in multiple directories. These scripts accepts arguments

start | stop | reload | status | restart.

/opt/xyz/x/X_FE.sh
/opt/xyz/x/X_BE.sh
/opt/xyz/y/Y_FE.sh
/opt/xyz/y/Y_BE.sh
/opt/xyz/z/Z_BE.sh


I wish to have a single bash script which accepts the same arguments and execute all the 5 scripts mentioned above.

/opt/singlescript.sh start ---- must execute all the 5 scripts with start argument.


Any help would be much appreciated.

Answer

It would look something like this. There are multiple ways to do this and this is just one way

#!/bin/bash
echo "invoking x/X_FE with $1"
sh /opt/xyz/x/X_FE.sh $1

echo "invoking x/X_BE with $1"
sh /opt/xyz/x/X_BE.sh $1

echo "invoking y/Y_FE with $1"
sh /opt/xyz/y/Y_FE.sh $1

echo "invoking x/Y_BE with $1"
sh /opt/xyz/y/Y_BE.sh $1

echo "invoking z/Z_FE with $1"
sh /opt/xyz/z/Z_BE.sh $1