系统环境:
- OS:CentOS-7-x86_64-Minimal-1908
- Kernel:3.10.0-1062.el7.x86_64 #1 SMP Wed Aug 7 18:08:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
- MySQL:mysql Ver 14.14 Distrib 5.6.50, for Linux (x86_64) using EditLine wrapper
- PHP:5.6.40 (cli) (built: May 13 2020 15:59:55)
- Nginx: nginx/1.18.0
脚本要求:
自动重启该游戏的所有区,且每个区重启的间隔时间要等于 15秒,同时,需要清理游戏目录下日志:
脚本 game_restart.sh
内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| #!/usr/bin/env bash game_dir='/data/game' function restart_server() { local server_dir="$1" local server_name="$2" if [ -d "${game_dir}/${server_dir}" ]; then cd "${game_dir}/${server_dir}" ./scripts/stop.sh > MainServer.log ./scripts/start.sh echo -e "\e[32m${server_name} 已经重启并清理了日志文件 ...\e[0m" fi }
restart_server "server" "第一个服:Server" echo "准备重启第二个服 ..." sleep 15
restart_server "server2" "第二个服:Server2" echo "准备重启第三个服 ..." sleep 15
restart_server "server3" "第三个服:Server3" echo "准备重启第四个服 ..." sleep 15
restart_server "server4" "第四个服:Server4" 该脚本如何执行
|