linux - 一次重启多个服务的Shell脚本
问题描述
需要使用 shell 脚本一次重新启动多个服务。我们现在手动进入每个文件夹(因为不同服务的文件位于不同的路径中)并使用命令重新启动它们。例如:
cd /opt/apps/service1 and run the command ./**** -start
对于 service2:转到文件夹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
推荐阅读
- python - 在 python 中打包时如何包含子模块的所有依赖项?
- json - Graph API - 消息 - API 为 eventMessageRequest 生成的无效 Json
- excel - 宏从多个工作簿中选择数据并复制到具有不同工作表的一个主工作簿中
- awk - 使用 awk 命令替换字段值时获得的重复结果
- python - 有没有办法从python中的列表内容自动创建类对象?
- r - 将数字中的月份更改为月份,例如 1 到 1 月、2 到 2 月等
- python - Removing specific blank lines from txt/srt files inside a directory and its sub-directories by python
- python - 错误类型错误:'NoneType' 对象不是 iterab
- django - 与 django 中的模板混淆
- bash - 在树莓派中永久更改终端颜色