简体   繁体   English

使用一个bash脚本在diff目录中执行多个bash脚本

[英]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. 我有多个bash脚本可以在多个目录中弹出Jboss实例。 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. 我希望有一个单独的bash脚本,它接受相同的参数并执行上面提到的所有5个脚本。

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

Any help would be much appreciated. 任何帮助将非常感激。

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

Using GNU Parallel it looks like: 使用GNU Parallel看起来像:

parallel ::: /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 ::: start
parallel ::: /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 ::: stop

If they cannot be run in parallel add -j1: 如果不能并行运行add -j1:

parallel -j1 ::: /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 ::: start

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM