2023-07-10 05:05:49 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# 定义一个函数来停止每个服务器的 screen 会话
|
|
|
|
stop_server() {
|
|
|
|
server_name=$1
|
|
|
|
echo "Stopping $server_name"
|
|
|
|
|
|
|
|
# 如果存在具有相同名称的 screen 会话,将其终止
|
|
|
|
existing_session=$(screen -ls | grep -w "$server_name")
|
|
|
|
if [ -n "$existing_session" ]; then
|
|
|
|
echo "Terminating screen session for $server_name"
|
|
|
|
screen -S "$server_name" -X quit
|
|
|
|
else
|
|
|
|
echo "No screen session found for $server_name"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# 列出所有服务器目录
|
2023-07-21 03:14:24 +00:00
|
|
|
server_dirs=() # 初始化一个空数组
|
|
|
|
|
|
|
|
for dir in server/*/ ; do # 遍历 "server/" 下的所有子目录
|
|
|
|
dir=${dir%*/} # 删除末尾的 "/"
|
|
|
|
dir=${dir##*/} # 删除开头的 "server/"
|
|
|
|
server_dirs+=("$dir") # 添加到数组
|
|
|
|
done
|
2023-07-10 05:05:49 +00:00
|
|
|
|
|
|
|
# 停止每个服务器的 screen 会话
|
|
|
|
for server_dir in "${server_dirs[@]}"; do
|
|
|
|
stop_server $server_dir
|
|
|
|
done
|