自动化部署-相关部署脚本

1.把所有的启动和关闭命令变成可执行文件

#!/bin/bash

root_dir="/home/mml3/app"

find "$root_dir" -type d -name "shbin" | while read shbin_dir; do
    echo "Setting executable permissions in $shbin_dir"
    chmod +x "$shbin_dir"/*
done

echo "All done."


2.根据机器不一样修改-Dsnowflake.datacenter.id和-Dsnowflake.worker.id的值把0改成1或者2

需要一个shell脚本来修改/home/mml3/app目录下每个子目录中shbin文件夹内的某个以start结尾的文件,特别是将文件中的-Dsnowflake.datacenter.id=0改为-Dsnowflake.datacenter.id=1,以及-Dsnowflake.worker.id=0改为-Dsnowflake.worker.id=1

下面是一个脚本会递归地查找所有以start结尾的文件,并使用sed命令来进行替换操作。

#!/bin/bash

# 指定目录路径
BASE_DIR="/home/mml3/app"

# 查找所有以'start'结尾的文件
find "$BASE_DIR" -type f -name "*start" | while read -r file; do
  # 检查文件是否在一个名为'shbin'的目录下
  if [[ "$file" == */shbin/*start ]]; then
    echo "Modifying $file"
    # 使用sed命令进行替换
    sed -i 's/-Dsnowflake.datacenter.id=0/-Dsnowflake.datacenter.id=1/g' "$file"
    sed -i 's/-Dsnowflake.worker.id=0/-Dsnowflake.worker.id=1/g' "$file"
  fi
done

echo "Modification complete."

3.批量开始,批量结束

下面是两个shell脚本:一个用于执行所有以start结尾的文件,另一个用于执行所有以stop结尾的文件。这些脚本将遍历/home/mml3/app目录下每个子目录中的shbin文件夹,查找符合条件的文件并执行它们。

开始脚本(start_script.sh)

#!/bin/bash

# 定位到 /home/mml3/app 目录
cd /home/mml3/app

# 遍历每个子目录下的 shbin 文件夹
find . -type d -name shbin | while read dir; do
  # 在每个 shbin 文件夹内查找以 start 结尾的文件并执行
  find "$dir" -type f -name '*start' | while read start_script; do
    echo "Executing $start_script"
    bash "$start_script"  # 使用 bash 命令执行文件
  done
done

停止脚本(stop_script.sh)

#!/bin/bash

# 定位到 /home/mml3/app 目录
cd /home/mml3/app

# 遍历每个子目录下的 shbin 文件夹
find . -type d -name shbin | while read dir; do
  # 在每个 shbin 文件夹内查找以 stop 结尾的文件并执行
  find "$dir" -type f -name '*stop' | while read stop_script; do
    echo "Executing $stop_script"
    bash "$stop_script"  # 使用 bash 命令执行文件
  done
done

使用说明:

  1. 将上述脚本保存为start_script.shstop_script.sh
  2. 通过在终端运行chmod +x start_script.sh stop_script.sh命令,给予这两个脚本执行权限。
  3. 使用./start_script.sh执行所有start结尾的文件,使用./stop_script.sh执行所有stop结尾的文件。
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ascarl2010

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值