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
使用说明:
- 将上述脚本保存为
start_script.sh
和stop_script.sh
。 - 通过在终端运行
chmod +x start_script.sh stop_script.sh
命令,给予这两个脚本执行权限。 - 使用
./start_script.sh
执行所有start
结尾的文件,使用./stop_script.sh
执行所有stop
结尾的文件。