交互式脚本结构大改

main
PC-202302260912\Administrator 2023-08-01 16:20:12 +08:00
parent b736349a70
commit 28f9a3dfdf
5 changed files with 493 additions and 559 deletions

View File

@ -1,28 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#########################################################################
# File Name: check_json.py
# Created on : 2019-04-18 10:43:28
# Author: Wu Kang
# Last Modified: 2019-04-18 10:55:38
# Description:
#########################################################################
import json
import sys
file=sys.argv[1]
def CheckJson(file):
try:
with open(file, 'r') as f:
load_dict = json.load(f)
except:
print("{} 非json文件!".format(file))
sys.exit(1)
else:
sys.exit(0)
CheckJson(file)

View File

@ -1,134 +0,0 @@
#!/bin/bash
source ../main.sh
show_file(){
filer=$1
#ls /data/update/$filer/ | tr ' ' '\n'
find /data/update/$filer -maxdepth 1 \( -type f -o -type d \) -printf "%-20f\t%TY-%Tm-%Td %TH:%TM:%TS\n"
}
# 判断一个字符串是否是合法的IP地址
is_valid_ip() {
local ip=$1
local pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$"
if [[ $ip =~ $pattern ]]; then
# 检查每个数字是否在0到255之间
local IFS='.'
read -ra octets <<< "$ip"
for octet in "${octets[@]}"; do
if (( octet < 0 || octet > 255 )); then
return 1
fi
done
return 0
else
return 1
fi
}
mod_package(){
ip=${1}
package=${2}
# 源服务器上的tar压缩包路径
source_tar="/data/update/package/"
# 游戏服目标服务器上的目标目录路径
destination_dir="/data/jieling/server"
echo "正在处理服务器 $ip"
scp "$source_tar/$package" "$ip:$destination_dir"
ssh "$ip" "tar -zxvf $destination_dir/$package -C $destination_dir"
ssh "$ip" "rm -rf $destination_dir/$package"
echo "处理完成服务器 $ip "
}
#正式服发送
send_package_reboot(){
package=${1}.tar.gz
ip_txt=${2}
reboot=${3}
if is_valid_ip "$ip_txt"; then
echo "$ip_txt 开始测试服更新"
mod_package $ip_txt $package
case $reboot in
0)
echo "热更,不需要重启... $i"
;;
1)
ssh $i "bash /data/jieling/server/bin/reboot.sh core1"
echo "重启测试服服务器 $i"
;;
esac
else
echo "$ip_txt 开始正式服更新"
for i in `awk '{print $2}' /data/update/script/txt/$ip_txt`
do
mod_package $i $package
case $reboot in
0)
echo "热更,不需要重启... $i"
;;
1)
ssh $i "supervisorctl restart all"
echo "重启正式服服务器 $i"
;;
esac
done
fi
}
#gm重启
gm_reboot(){
ip=${1}
ssh $ip "bash /data/jieling/gm/gm_reboot.sh"
ssh $ip "ps -ef|grep gm_tw_admin"
echo "gm重启完毕"
}
mod_gm_package(){
ip=${1}
package=gm.tar.gz
# 源服务器上的tar压缩包路径
source_tar="/data/update/project/miduo_gm/gm"
# 游戏服目标服务器上的目标目录路径
destination_dir="/data/jieling/gm"
if [ -e $source_tar ]; then
echo "正在处理服务器 $ip"
scp "$source_tar/$package" "$ip:$destination_dir"
ssh "$ip" "tar -zxvf $destination_dir/$package -C $destination_dir"
ssh "$ip" "rm -f $destination_dir/$package"
echo "处理完成服务器 $ip "
else
echo "gm.tar.gz 不存在,请先去打包 "
gm
fi
}
#gm 发送包
gm_send_package(){
ip_txt=${1}
if is_valid_ip "$ip_txt"; then
echo "$ip_txt 开始更新gm/ip"
mod_gm_package $ip_txt
read -r -p "更新完毕是否需要重启Y/N: " input
case $input in
[yY][eE][sS]|[yY])
gm_reboot $ip
;;
*)
echo "over..."
exit 0
;;
esac
else
echo "$ip_txt 开始更新gm/txt"
for i in `awk '{print $2}' /data/update/script/txt/$ip_txt`
do
mod_gm_package $i
gm_reboot $i
done
fi
}

View File

@ -34,9 +34,20 @@ cd ${BASE_DIR}/miduo_server || exit
git branch
git pull
#使用前需要使用 sudo yum install jq 安装jq工具
check_json(){
path=${1}
if jq empty "${path}"; then
echo "${path}文件是有效的JSON格式。"
else
echo "${path}文件不是有效的JSON格式。"
exit 0
fi
}
#校验文件
/data/update/script/check_json.py ${BASE_DIR}/miduo_server/conf/hotfix.json || exit
/data/update/script/check_json.py ${BASE_DIR}/miduo_server/conf/c_database_version.json || exit
check_json ${BASE_DIR}/miduo_server/conf/hotfix.json
check_json ${BASE_DIR}/miduo_server/conf/c_database_version.json
cd ${BASE_DIR}/miduo_protocol || exit
git branch

809
main.sh
View File

@ -1,28 +1,446 @@
#!/bin/bash
#删除命令乱码解决
# 删除命令乱码解决
stty erase ^h
#引用其他文件
source function/function.sh
# 定义ANSI颜色转义码
#red='\033[0;31m' #红色
#green='\033[0;32m' #绿色
#yellow='\033[0;33m' #黄色
#NC='\033[0m'
#文字颜色:
# 文字颜色
red='\033[31m'
green='\033[32m'
yellow='\033[33m'
blue='\033[34m'
# shellcheck disable=SC2034
purple='\033[35m'
# shellcheck disable=SC2034
cyan='\033[36m'
# shellcheck disable=SC2034
white='\033[37m'
NC='\033[0m' # 恢复默认颜色
# 定义函数,用于展示菜单选项
# 判断一个字符串是否是合法的IP地址
is_valid_ip() {
local ip=$1
local pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$"
if [[ $ip =~ $pattern ]]; then
# 检查每个数字是否在0到255之间
local IFS='.'
read -ra octets <<< "$ip"
for octet in "${octets[@]}"; do
if (( octet < 0 || octet > 255 )); then
return 1
fi
done
return 0
else
return 1
fi
}
# 显示指定目录下的文件或目录
show_file(){
filer=$1
find /data/update/"$filer" -maxdepth 1 \( -type f -o -type d \) -printf "%-20f\t%TY-%Tm-%Td %TH:%TM:%TS\n"
}
# 发包并解压缩
unzip_package(){
# 服务器地址
local ip=${1}
# tar 包名
local package=${2}.tar.gz
# 源服务器上的tar压缩包路径
local source_tar=${3}
# 游戏服目标服务器上的目标目录路径
local destination_dir=${4}
if [ -e $source_tar ]; then
echo "正在处理服务器 $ip"
scp "$source_tar/$package" "$ip:$destination_dir"
ssh "$ip" "tar -zxvf $destination_dir/$package -C $destination_dir"
ssh "$ip" "rm -f $destination_dir/$package"
echo "处理完成服务器 $ip "
else
echo "$source_tar/$package 不存在,请先去打包!"
gm
fi
}
# 通用的重启函数
restart_server() {
local server_name=$1
local ip=$2
local restart_script=""
case $server_name in
"tomcat")
restart_script="bash /usr/local/apache-tomcat-7.0.79/login_reboot.sh"
;;
"delivery")
restart_script="bash /data/jieling/delivery-server/pay_reboot.sh"
;;
"sensitive")
restart_script="bash /data/jieling/sensitiveWordFilter/bin/mingan_reboot.sh"
;;
"admin")
restart_script="bash /data/jieling/gm/gm_reboot.sh"
;;
"core")
restart_script="supervisorctl restart all"
;;
*)
echo -e "${red}无效的服务器名称${NC}"
exit 1
;;
esac
ssh "$ip" "$restart_script"
ssh "$ip" "ps -ef | grep $server_name"
echo "${server_name}重启完成"
}
# 发送包并重启
game_send_package() {
local channel=${1}
local package=${2}.tar.gz
local reboot=${3}
local source_tar="/data/update/package/"
local destination_dir="/data/jieling/server"
if is_valid_ip "$channel"; then
unzip_package $channel $package $source_tar $destination_dir
if [[ $reboot -eq 1 ]]; then
restart_server "core" "$channel"
fi
else
cat "$channel" | while read -r ip; do
unzip_package $channel $package $source_tar $destination_dir
if [[ $reboot -eq 1 ]]; then
restart_server "core" "$ip"
fi
done
fi
}
# 更新gm
gm_send_package() {
local channel=${1}
local package=gm.tar.gz
local source_tar="/data/update/project/miduo_gm/gm"
local destination_dir="/data/jieling/gm"
if is_valid_ip "$channel"; then
unzip_package $channel $package $source_tar $destination_dir
else
cat "$channel" | while read -r ip; do
unzip_package $ip $package $source_tar $destination_dir
done
fi
}
# 通用游戏服更新函数
game_update_option() {
local action=$1
case $action in
"update")
local action_desc="打更新包"
local script="update_game.sh"
;;
"hotfix")
local action_desc="打热更包"
local script="hotfix_game.sh"
;;
"official_hotfix")
local action_desc="正式服热更"
local script="hotfix_game.sh"
local send_to="txt"
local reboot=0
;;
"official_reboot")
local action_desc="正式服停服更新"
local script="hotfix_game.sh"
local send_to="txt"
local reboot=1
;;
"test_hotfix")
local action_desc="测试服热更"
local script="hotfix_game.sh"
local send_to="ip"
local reboot=0
;;
"test_reboot")
local action_desc="测试服停服更新"
local script="hotfix_game.sh"
local send_to="ip"
local reboot=1
;;
*)
echo -e "${red}无效的选项,请重新输入${NC}"
show_menu
handle_input
return
;;
esac
echo -e "${yellow}$action_desc${NC}"
echo "=============================="
show_file project
read -rp "请输入项目地址: " project
if [ -z "$project" ]; then
echo -e "${red}项目地址不能为空,请重新输入${NC}"
return
fi
show_file package
read -rp "请输入包名(不需要带文件后缀): " package
if [ -z "$package" ]; then
echo -e "${red}包名不能为空,请重新输入${NC}"
return
fi
echo -e "开始执行操作 项目:$project, 包名:$package"
if [ "$send_to" = "txt" ]; then
show_file script/txt
read -rp "请输入文件名称(不需要带文件后缀): " channel
echo -e "开始发送 包名:$package, channel$channel"
game_send_package "${channel}.txt" "$package" "$reboot"
elif [ "$send_to" = "ip" ]; then
read -rp "请输入游戏服ip: " ip
echo -e "开始发送 包名:$package, ip$ip"
game_send_package "$ip" "$package" "$reboot"
else
bash "$script" "$project" "$package"
fi
}
# 通用GM更新函数
gm_option() {
local action=$1
case $action in
"package")
local action_desc="打包"
local script="update_gm.sh"
;;
"single_update")
local action_desc="单机器更新"
local send_to="ip"
;;
"batch_update")
local action_desc="批量更新"
local send_to="txt"
;;
"single_reboot")
local action_desc="单机器重启"
;;
"batch_reboot")
local action_desc="批量重启"
;;
*)
echo -e "${red}无效的选项,请重新输入${NC}"
show_menu
handle_input
return
;;
esac
echo -e "${yellow}$action_desc${NC}"
if [ "$action" = "package" ]; then
show_file project
read -rp "请输入表所在游戏项目地址: " project
bash "$script" "$project"
echo -e "gm打包完成"
elif [ "$action" = "single_update" ]; then
read -rp "请输入游戏服ip: " ip
echo -e "开始更新gm"
gm_send_package "$ip"
elif [ "$action" = "batch_update" ]; then
echo -e "开始更新gm"
gm_send_package gm_ip.txt
elif [ "$action" = "single_reboot" ]; then
read -rp "请输入游戏服ip: " ip
echo -e "开始重启gm"
restart_server "admin" "$ip"
elif [ "$action" = "batch_reboot" ]; then
echo -e "开始更新gm"
while read -r ip; do
restart_server "admin" "$ip"
done < gm_ip.txt
fi
}
# 通用的更新函数
update_server() {
local server_name=$1
local update_script=$2
echo -e "${yellow}${server_name}更新${NC}"
read -rp "请输入${server_name}的ip地址: " ip
echo -e "开始更新${server_name}ip$ip"
bash "${update_script}" "$ip"
read -r -p "更新完毕是否需要重启Y/N: " input
case $input in
[yY][eE][sS]|[yY])
restart_server "$server_name" "$ip"
;;
*)
echo "over..."
exit 0
;;
esac
}
# 通用的重启判断函数
restart_bol() {
local server_name=$1
echo -e "${yellow}${server_name}重启${NC}"
read -rp "请输入${server_name}的ip地址: " ip
echo -e "开始重启${server_name}ip$ip"
restart_server "$server_name" "$ip"
}
# 退出脚本
exit_script() {
echo -e "${red}谢谢使用,再见!${NC}"
exit 0
}
# 游戏服更新子菜单
game_menu(){
echo -e "================================"
echo -e "开始更新${green}游戏服${NC}"
echo -e "1. ${yellow}打更新包${NC}"
echo -e "2. ${yellow}打热更包${NC}"
echo -e "3. ${yellow}正式服热更${NC}"
echo -e "4. ${yellow}正式服停服更新${NC}"
echo -e "5. ${yellow}测试服热更${NC}"
echo -e "6. ${yellow}测试服停服更新${NC}"
echo -e "0. ${green}返回主菜单${NC}"
echo -e "*. ${red}其他任意键退出程序${NC}"
}
# 游戏服更新
update_game(){
while true; do
game_menu
read -rp "请输入选项编号: " choice
case $choice in
1) game_update_option "update" ;; # 游戏服更新:打更新包
2) game_update_option "hotfix" ;; # 游戏服更新:打热更包
3) game_update_option "official_hotfix" ;; # 游戏服更新:正式服热更
4) game_update_option "official_reboot" ;; # 游戏服更新:正式服停服更新
5) game_update_option "test_hotfix" ;; # 游戏服更新:测试服热更
6) game_update_option "test_reboot" ;; # 游戏服更新:测试服停服更新
0) return ;;
*) exit_script ;;
esac
done
}
# gm更新子菜单
gm_menu(){
echo -e "================================"
echo -e "开始更新${green}gm服${NC}"
echo -e "1. ${yellow}打包${NC}"
echo -e "2. ${yellow}单机器更新${NC}"
echo -e "3. ${yellow}批量更新${NC}"
echo -e "4. ${yellow}单机器重启${NC}"
echo -e "5. ${yellow}批量重启${NC}"
echo -e "0. ${green}返回主菜单${NC}"
echo -e "*. ${red}其他任意键退出程序${NC}"
}
# gm更新
update_gm(){
while true; do
gm_menu
read -rp "请输入选项编号: " choice
case $choice in
1) gm_option "package" ;; # GM更新打包
2) gm_option "single_update" ;; # GM更新单机器更新
3) gm_option "batch_update" ;; # GM更新批量更新
4) gm_option "single_reboot" ;; # GM更新单机器重启
5) gm_option "batch_reboot" ;; # GM更新批量重启
0) return ;;
*) exit_script ;;
esac
done
}
# 登陆服更新子菜单
login_menu(){
echo -e "================================"
echo -e "开始更新${green}登陆服${NC}"
echo -e "1. ${yellow}更新登陆服代码${NC}"
echo -e "2. ${yellow}重启登陆服${NC}"
echo -e "0. ${green}返回主菜单${NC}"
echo -e "*. ${red}其他任意键退出程序${NC}"
}
# 登陆服更新
login(){
while true; do
login_menu
read -rp "请输入选项编号: " choice
case $choice in
1) update_server "tomcat" "update_login.sh" ;;
2) restart_bol "tomcat" ;;
0) return ;;
*) exit_script ;;
esac
done
}
# 支付服更新子菜单
pay_menu(){
echo -e "================================"
echo -e "开始更新${green}支付服${NC}"
echo -e "1. ${yellow}更新支付服代码${NC}"
echo -e "2. ${yellow}重启支付服${NC}"
echo -e "0. ${green}返回主菜单${NC}"
echo -e "*. ${red}其他任意键退出程序${NC}"
}
# 支付服更新
pay(){
while true; do
pay_menu
read -rp "请输入选项编号: " choice
case $choice in
1) update_server "delivery" "update_delivery.sh" ;;
2) restart_bol "delivery" ;;
0) return ;;
*) exit_script ;;
esac
done
}
# 敏感词服菜单
mingan_menu(){
echo -e "================================"
echo -e "开始更新${green}敏感词服${NC}"
echo -e "1. ${yellow}更新敏感词服代码${NC}"
echo -e "2. ${yellow}重启敏感词服${NC}"
echo -e "0. ${green}返回主菜单${NC}"
echo -e "*. ${red}其他任意键退出程序${NC}"
}
# 敏感词服更新
mingan(){
while true; do
mingan_menu
read -rp "请输入选项编号: " choice
case $choice in
1) update_server "sensitive" "update_sensitive.sh" ;;
2) restart_bol "sensitive" ;;
0) return ;;
*) exit_script ;;
esac
done
}
# 展示菜单选项
show_menu() {
echo -e "================================"
echo -e "欢迎使用${blue}戒灵更新脚本${NC}"
@ -34,360 +452,27 @@ show_menu() {
echo -e "0. ${red}退出${NC}"
}
# 定义函数,用于处理用户输入
# 处理用户输入
handle_input() {
read -p "请输入选项编号: " choice
read -rp "请输入选项编号: " choice
case $choice in
1)
# 在这里编写选项一的代码
game
;;
2)
echo -e "${yellow}开始更新gm服${NC}"
# 在这里编写选项二的代码
gm
;;
3)
echo -e "${yellow}开始更新登陆服${NC}"
# 在这里编写选项三的代码
login
;;
4)
echo -e "${yellow}开始更新支付服${NC}"
# 在这里编写选项四的代码
pay
;;
5)
echo -e "${yellow}开始更新敏感词服${NC}"
# 在这里编写选项五的代码
mingan
;;
0)
echo -e "${red}谢谢使用,再见!${NC}"
exit 0
;;
*)
echo -e "${red}无效的选项,请重新输入${NC}"
handle_input
;;
1) update_game ;;
2) update_gm ;;
3) login ;;
4) pay ;;
5) mingan ;;
0) exit_script ;;
*) echo -e "${red}无效的选项,请重新输入${NC}" ;;
esac
}
#游戏服更新
game(){
echo -e "================================"
echo -e "开始更新${green}游戏服${NC}"
echo -e "1. ${yellow}打更新包${NC}"
echo -e "2. ${yellow}打热更包${NC}"
echo -e "3. ${yellow}正式服热更${NC}"
echo -e "4. ${yellow}正式服停服更新${NC}"
echo -e "5. ${yellow}测试服热更${NC}"
echo -e "6. ${yellow}测试服停服更新${NC}"
echo -e "0. ${green}返回主菜单${NC}"
echo -e "*. ${red}其他任意键退出程序${NC}"
read -p "请输入选项编号: " choice
case $choice in
1)
echo -e "${yellow}打更新包${NC}"
echo "=============================="
show_file project
read -p "请输入项目地址: " project
show_file package
read -p "请输入包名(不需要带文件后缀): " package
echo -e "开始打包 项目:$project, 包名:$package"
bash update_game.sh $project $package
game
;;
2)
echo -e "${yellow}打热更包${NC}"
echo "=============================="
show_file project
read -p "请输入项目地址: " project
show_file package
read -p "请输入包名(不需要带文件后缀): " package
echo -e "开始打包 项目:$project, 包名:$package"
bash hotfix_game.sh $project $package
game
;;
3)
echo -e "${yellow}正式服热更${NC}"
echo "=============================="
show_file package
read -p "请输入包名(不需要带文件后缀): " package
show_file script/txt
read -p "请输入文件名称(不需要带文件后缀): " channel
echo -e "开始发送 包名:$package, channel$channel"
send_package_reboot $package ${channel}.txt 0
game
;;
4)
echo -e "${yellow}正式服停服更新${NC}"
echo "=============================="
show_file package
read -p "请输入包名(不需要带文件后缀): " package
show_file script/txt
read -p "请输入文件名称(不需要带文件后缀): " channel
echo -e "开始发送 包名:$package, channel$channel"
send_package_reboot $package ${channel}.txt 1
game
;;
5)
echo -e "${yellow}测试服热更${NC}"
echo "=============================="
show_file package
read -p "请输入包名(不需要带文件后缀): " package
read -p "请输入游戏服ip: " ip
echo -e "开始发送 包名:$package, ip$ip"
send_package_reboot $package $ip 0
game
;;
6)
echo -e "${yellow}测试服停服更新${NC}"
echo "=============================="
show_file package
read -p "请输入包名(不需要带文件后缀): " package
read -p "请输入游戏服ip: " ip
echo -e "开始发送 包名:$package, ip$ip"
send_package_reboot $package $ip 1
game
;;
0)
show_menu
handle_input
;;
*)
echo -e "${red}谢谢使用,再见!${NC}"
exit 0
;;
esac
# 主程序入口
main() {
while true; do
show_menu
handle_input
done
}
#gm更新
gm(){
txt=gm_ip.txt
echo -e "================================"
echo -e "开始更新${green}gm服${NC}"
echo -e "1. ${yellow}打包${NC}"
echo -e "2. ${yellow}单机器更新${NC}"
echo -e "3. ${yellow}批量更新${NC}"
echo -e "4. ${yellow}单机器重启${NC}"
echo -e "5. ${yellow}批量重启${NC}"
echo -e "0. ${green}返回主菜单${NC}"
echo -e "*. ${red}其他任意键退出程序${NC}"
read -p "请输入选项编号: " choice
case $choice in
1)
echo -e "${yellow}打包${NC}"
show_file project
read -p "请输入表所在游戏项目地址: " project
bash update_gm.sh $project
echo -e "gm打包完成"
gm
;;
2)
echo -e "${yellow}单机器更新${NC}"
read -p "请输入游戏服ip: " ip
echo -e "开始更新gm"
gm_send_package $ip
gm
;;
3)
echo -e "${yellow}批量更新${NC}"
echo -e "开始更新gm"
gm_send_package $txt
gm
;;
4)
echo -e "${yellow}单机器重启${NC}"
read -p "请输入游戏服ip: " ip
echo -e "开始重启gm"
gm_reboot $ip
gm
;;
5)
echo -e "${yellow}批量重启${NC}"
echo -e "开始更新gm"
for i in `awk '{print $2}' /data/update/script/txt/$txt`
do
gm_reboot $i
done
gm
;;
0)
show_menu
handle_input
;;
*)
echo -e "${red}谢谢使用,再见!${NC}"
exit 0
;;
esac
}
#登陆 ssh $i "sh /data/jieling/gm/gm_restart.sh"
login(){
echo -e "================================"
echo -e "开始更新${green}登陆服${NC}"
echo -e "1. ${yellow}更新登陆服代码${NC}"
echo -e "2. ${yellow}重启登陆服${NC}"
echo -e "0. ${green}返回主菜单${NC}"
echo -e "*. ${red}其他任意键退出程序${NC}"
read -p "请输入选项编号: " choice
case $choice in
1)
echo -e "${yellow}登陆服更新${NC}"
read -p "请输入登陆服ip: " ip
echo -e "开始更新登陆服 ip$ip"
bash update_login.sh $ip
read -r -p "更新完毕是否需要重启Y/N: " input
case $input in
[yY][eE][sS]|[yY])
login_reboot $ip
;;
*)
echo "over..."
exit 0
;;
esac
login
;;
2)
echo -e "${yellow}登陆服重启${NC}"
read -p "请输入登陆服ip: " ip
echo -e "开始重启登陆服 ip$ip"
login_reboot
login
;;
0)
show_menu
handle_input
;;
*)
echo -e "${red}谢谢使用,再见!${NC}"
exit 0
;;
esac
}
login_reboot(){
ip=${1}
ssh $ip "bash /usr/local/apache-tomcat-7.0.79/login_reboot.sh"
ssh $ip "ps -ef|grep tomcat"
echo "登陆服重启完毕"
}
#支付
pay(){
echo -e "================================"
echo -e "开始更新${green}支付服${NC}"
echo -e "1. ${yellow}更新支付服代码${NC}"
echo -e "2. ${yellow}重启支付服${NC}"
echo -e "0. ${green}返回主菜单${NC}"
echo -e "*. ${red}其他任意键退出程序${NC}"
read -p "请输入选项编号: " choice
case $choice in
1)
echo -e "${yellow}支付服更新${NC}"
read -p "请输入支付服ip: " ip
echo -e "开始更新支付服 ip$ip"
bash update_delivery.sh $ip
read -r -p "更新完毕是否需要重启Y/N: " input
case $input in
[yY][eE][sS]|[yY])
pay_reboot $ip
;;
*)
echo "over..."
exit 0
;;
esac
pay
;;
2)
echo -e "${yellow}支付服重启${NC}"
read -p "请输入支付服ip: " ip
echo -e "开始重启支付服 ip$ip"
pay_reboot $ip
login
;;
0)
show_menu
handle_input
;;
*)
echo -e "${red}谢谢使用,再见!${NC}"
exit 0
;;
esac
}
pay_reboot(){
ip=${1}
ssh $ip "bash /data/jieling/delivery-server/pay_reboot.sh"
ssh $ip "ps -ef|grep delivery"
echo "支付服重启完毕"
}
#敏感词
mingan(){
echo -e "================================"
echo -e "开始更新${green}敏感词服${NC}"
echo -e "1. ${yellow}更新敏感词服代码${NC}"
echo -e "2. ${yellow}重启敏感词服${NC}"
echo -e "0. ${green}返回主菜单${NC}"
echo -e "*. ${red}其他任意键退出程序${NC}"
read -p "请输入选项编号: " choice
case $choice in
1)
echo -e "${yellow}敏感词服更新${NC}"
read -p "请输入敏感词服ip: " ip
echo -e "开始更新敏感词服 ip$ip"
bash update_sensitive.sh $ip
read -r -p "更新完毕是否需要重启Y/N: " input
case $input in
[yY][eE][sS]|[yY])
mingan_reboot $ip
;;
*)
echo "over..."
exit 0
;;
esac
mingan
;;
2)
echo -e "${yellow}敏感词服重启${NC}"
read -p "请输入敏感词服ip: " ip
echo -e "开始重启敏感词服 ip$ip"
mingan_reboot
login
;;
0)
show_menu
handle_input
;;
*)
echo -e "${red}谢谢使用,再见!${NC}"
exit 0
;;
esac
}
mingan_reboot(){
ip=${1}
ssh $ip "bash /data/jieling/sensitiveWordFilter/bin/mingan_reboot.sh"
ssh $ip "ps -ef|grep sensitive"
echo "敏感字服重启完毕"
}
# 主循环,展示菜单并处理用户输入
while true; do
show_menu
handle_input
done
# 脚本开始执行
main

View File

@ -1,33 +1,33 @@
#!/bin/bash
name=$1
ip=$2
package=${name}.tar.gz
# 源服务器上的tar压缩包路径
source_tar="/data/update/package/"
# 目标服务器
destination_server=txt/server_ip.txt
# 目标服务器上的目标目录路径
destination_dir="/data/"
# 单服务器更新
if [ ! -z $ip ];then
echo "正在处理服务器 $ip "
scp "$source_tar/$package" "$ip:$destination_dir"
ssh "$ip" "tar -zxvf $destination_dir/$package -C $destination_dir/jieling/server/"
ssh "$ip" "rm -rf $destination_dir/$package"
echo "处理完成服务器 $ip "
else
# 循环遍历源服务器列表
for i in `awk '{print $2}' /data/update/script/$destination_server`
do
echo "正在处理服务器 $i "
scp "$source_tar/$package" "$i:$destination_dir"
ssh "$i" "tar -zxvf $destination_dir/$package -C $destination_dir/jieling/server/"
ssh "$i" "rm -rf $destination_dir/$package"
echo "处理完成服务器 $i "
done
fi
##!/bin/bash
#
#name=$1
#ip=$2
#package=${name}.tar.gz
#
## 源服务器上的tar压缩包路径
#source_tar="/data/update/package/"
#
## 目标服务器
#destination_server=txt/server_ip.txt
#
## 目标服务器上的目标目录路径
#destination_dir="/data/"
#
## 单服务器更新
#if [ ! -z $ip ];then
# echo "正在处理服务器 $ip "
# scp "$source_tar/$package" "$ip:$destination_dir"
# ssh "$ip" "tar -zxvf $destination_dir/$package -C $destination_dir/jieling/server/"
# ssh "$ip" "rm -rf $destination_dir/$package"
# echo "处理完成服务器 $ip "
#else
## 循环遍历源服务器列表
# for i in `awk '{print $2}' /data/update/script/$destination_server`
# do
# echo "正在处理服务器 $i "
# scp "$source_tar/$package" "$i:$destination_dir"
# ssh "$i" "tar -zxvf $destination_dir/$package -C $destination_dir/jieling/server/"
# ssh "$i" "rm -rf $destination_dir/$package"
# echo "处理完成服务器 $i "
# done
#fi