Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 一次重新启动多个服务的Shell脚本_Linux_Shell_Unix - Fatal编程技术网

Linux 一次重新启动多个服务的Shell脚本

Linux 一次重新启动多个服务的Shell脚本,linux,shell,unix,Linux,Shell,Unix,需要使用shell脚本一次重新启动多个服务。我们现在手动进入每个文件夹(因为不同服务的文件位于不同的路径中),并使用命令重新启动它们。 例如: cd/opt/apps/service1并运行命令。/**-start 对于服务2: 转到文件夹cd/opt/apps/service2 然后执行命令/**-start这个演示bash脚本应该适合您 #!/bin/bash services=( # path, restart cmd "/deploy/service1, ./svr1

需要使用shell脚本一次重新启动多个服务。我们现在手动进入每个文件夹(因为不同服务的文件位于不同的路径中),并使用命令重新启动它们。 例如:

cd/opt/apps/service1并运行命令。/**-start

对于服务2: 转到文件夹
cd/opt/apps/service2


然后执行命令
/**-start

这个演示bash脚本应该适合您

#!/bin/bash

services=(
    # path, restart cmd
    "/deploy/service1, ./svr1 restart"
    "/deploy/service2, ./super_svr -s"
    "/deploy/service3, python ./svr3 restart"
)


for ((i = 0; i < ${#services[@]}; i++))
do
    entry="${services[$i]}"
    path=`echo $entry | cut -d',' -f1`
    cmd=`echo $entry | cut -d',' -f2`
    pushd $path
    $cmd
    popd
done
#/bin/bash
服务=(
#路径,重新启动cmd
/deploy/service1,/svr1重新启动
“/deploy/service2,./super_svr-s”
/deploy/service3,python./svr3重新启动
)
对于((i=0;i<${服务[@]};i++)
做
entry=“${services[$i]}”
路径=`echo$entry | cut-d','-f1`
cmd=`echo$entry | cut-d','-f2`
pushd$path
$cmd
邻苯二胺
完成

使用支持数据清晰地迭代您的需求。另外,请分享到目前为止您所编写的代码。嗯,不重新发明轮子和编写systemd单元文件,定义适当的依赖项,在系统启动时启用它们如何?