此脚本分为两部分,一是批量创建xshell的session;二是批量修改配置文件;
-
#!/bin/bash
-
IP="([0-9]{1,3}\.){3}[0-9]{1,3}"
-
PORT="([0-9]{5})"
-
CSV_FILE="create_xshell.csv"
-
#create xshell session
-
create_xshell ()
-
{
-
local XSH=`find . -maxdepth 1 -type f -name "*.xsh"`
-
local ROLE=('' '' gl map1 map2 map3)
-
#local XSH_IP=`echo "$XSH"|grep -Eo "$IP"`
-
local XSH_VALUE=`find . -maxdepth 1 -type f -name "*.xsh"|wc -l`
-
if [[ "${XSH##*.}" = "xsh" ]] && [[ $XSH_VALUE -eq 1 ]];then
-
echo "$XSH file is exist!!"
-
else
-
echo "*.xsh is not exist!!"
-
exit 1
-
fi
-
#
-
if [[ -f "$CSV_FILE" ]];then
-
echo "$CSV_FILE is exist!!"
-
else
-
echo "$CSV_FILE is not exist!!"
-
exit 5
-
fi
-
#
-
dos2unix $CSV_FILE
-
#sed 's/\\r//g' -i $CSV_FILE
-
#fi
-
while read line
-
do
-
local GAME_INFO=($(echo $line|awk -F"," '{print $1,$2,$3,$4,$5,$6}'))
-
if [[ -n $line ]];then
-
# echo "$line" |sed 's/\\r//g'
-
local LINE_FRONT=`echo $line |grep -o "^#"`
-
if [ "$LINE_FRONT" = "#" ];then
-
continue
-
else
-
for ((i=2;i<=5;i++))
-
do
-
cp ${XSH} ${GAME_INFO[0]}-${GAME_INFO[1]}-${GAME_INFO[$i]}-${ROLE[$i]}.xsh
-
sed -r "/Host/s/$IP/${GAME_INFO[$i]}/" -i ${GAME_INFO[0]}-${GAME_INFO[1]}-${GAME_INFO[$i]}-${ROLE[$i]}.xsh
-
done
-
mkdir -p session/${GAME_INFO[0]} && mv ${GAME_INFO[0]}-${GAME_INFO[1]}*.xsh session/${GAME_INFO[0]}
-
fi
-
else
-
echo "$line is not null!"
-
exit 1
-
fi
-
done <"$CSV_FILE"
-
}
-
#create base config
-
create_base_config ()
-
{
-
local CONFIG_ZIP=`ls |grep -E "[0-9]{4}.zip"`
-
if `ls |grep -qE "[0-9]{4}.zip"`;then
-
echo "config zip is exist!"
-
unzip $CONFIG_ZIP -d .
-
else
-
echo "config zip is not exist!"
-
exit 2
-
fi
-
local BASE_CONFIG_FILE=(BaseServerConfig.ini DBConfig.ini GMConfig.tab WorldIndex.ini)
-
local NO_CONFIG_FILE=(DBShareConfig.ini GameToggleConfig.ini ExtServerConfig.ini MultiGroupConfig.ini GameConfig.ini ServerIndex.ini)
-
while read line;
-
do
-
local BASE_CONFIG=(`echo $line|awk -F',' '{print $1,$3,$4,$5,$6,$7,$8,$9,$10,$11}'`)
-
local CONFIG_NUM=`ls |grep -E "*.ini|*.tab"|wc -l`
-
local LINE_FRONT=`echo $line |grep -o "^#"`
-
if [ "$LINE_FRONT" = "#" ];then
-
continue
-
else
-
if [[ "$CONFIG_NUM" -eq 10 ]];then
-
echo "alter ${BASE_CONFIG_FILE[0]} ..."
-
# grep -A3 "Server6" ${BASE_CONFIG_FILE[0]}|sed -i "/IP/s/$IP/${BASE_CONFIG[1]}/g" ${BASE_CONFIG_FILE[0]}
-
sed -ri "/Server6/{n;N;n;s/$IP/${BASE_CONFIG[1]}/;}" ${BASE_CONFIG_FILE[0]}
-
# grep -EA3 "Server0|Server4" ${BASE_CONFIG_FILE[0]}|sed -i "/IP/s/$IP/${BASE_CONFIG[2]}/g" ${BASE_CONFIG_FILE[0]}
-
sed -ri "/Server0/{n;N;n;s/$IP/${BASE_CONFIG[2]}/;};/Server4/{n;N;n;s/$IP/${BASE_CONFIG[2]}/;}" ${BASE_CONFIG_FILE[0]}
-
# grep -EA3 "Server1|Server3" ${BASE_CONFIG_FILE[0]}|sed -i "/IP/s/$IP/${BASE_CONFIG[3]}/g" ${BASE_CONFIG_FILE[0]}
-
sed -ri "/Server1/{n;N;n;s/$IP/${BASE_CONFIG[3]}/;};/Server3/{n;N;n;s/$IP/${BASE_CONFIG[3]}/;}" ${BASE_CONFIG_FILE[0]}
-
# grep -EA3 "Server2|Server5" ${BASE_CONFIG_FILE[0]}|sed -i "/IP/s/$IP/${BASE_CONFIG[4]}/g" ${BASE_CONFIG_FILE[0]}
-
sed -ri "/Server2/{n;N;n;s/$IP/${BASE_CONFIG[4]}/;};/Server5/{n;N;n;s/$IP/${BASE_CONFIG[4]}/;}" ${BASE_CONFIG_FILE[0]}
-
# grep -EA1 "DBCenter|GLServer" ${BASE_CONFIG_FILE[0]}|sed -i "/IP/s/$IP/${BASE_CONFIG[5]}/g" ${BASE_CONFIG_FILE[0]}
-
sed -ri "/DBCenter/,/Server0/s/$IP/${BASE_CONFIG[5]}/" ${BASE_CONFIG_FILE[0]}
-
# grep -A1 "AUServer" ${BASE_CONFIG_FILE[0]}|sed -i "/IP/s/$IP/${BASE_CONFIG[6]}/" ${BASE_CONFIG_FILE[0]}
-
sed -ri "/AUServer/{n;s/$IP/${BASE_CONFIG[6]}/;}" ${BASE_CONFIG_FILE[0]}
-
# grep -A1 "Billing" ${BASE_CONFIG_FILE[0]}|sed -i "/IP/s/$IP/${BASE_CONFIG[7]}/" ${BASE_CONFIG_FILE[0]}
-
sed -ri "/Billing/{n;s/$IP/${BASE_CONFIG[7]}/;}" ${BASE_CONFIG_FILE[0]}
-
sed -ri "/Billing/{N;n;s/${PORT}/${BASE_CONFIG[9]}/;}" ${BASE_CONFIG_FILE[0]}
-
echo "alter ${BASE_CONFIG_FILE[1]} ..."
-
# grep -A4 "System" ${BASE_CONFIG_FILE[1]}|sed -ri "/DBUser/s/(dbcenter)[0-9]{4}/\1"$ID"/" ${BASE_CONFIG_FILE[1]}
-
sed -ri "/System/{N;n;n;n;s/(dbcenter)[0-9]{4}/\1${BASE_CONFIG[0]}/;}" ${BASE_CONFIG_FILE[1]}
-
# grep -A2 "DBLog" ${BASE_CONFIG_FILE[1]}|sed -ri "/DBUser/s/(dbcenter)[0-9]{,4}/\1"${BASE_CONFIG[8]}"/" ${BASE_CONFIG_FILE[1]}
-
sed -ri "/\[DBLog\]/{N;n;s/(dbcenter)[0-9]{1,2}/\1${BASE_CONFIG[8]}/;}" ${BASE_CONFIG_FILE[1]}
-
echo "alter ${BASE_CONFIG_FILE[2]} ..."
-
sed -ri "s/^[0-9]{4}/"${BASE_CONFIG[0]}"/" ${BASE_CONFIG_FILE[2]}
-
echo "alter ${BASE_CONFIG_FILE[3]} ..."
-
sed -ri "/GLServerID/s/[0-9]{4}/"${BASE_CONFIG[0]}"/" ${BASE_CONFIG_FILE[3]}
-
mkdir -p config/${BASE_CONFIG[0]} && cp ${BASE_CONFIG_FILE[*]} ${NO_CONFIG_FILE[*]} config/${BASE_CONFIG[0]}
-
zip config/${BASE_CONFIG[0]}.zip ${BASE_CONFIG_FILE[*]} ${NO_CONFIG_FILE[*]}
-
else
-
echo "base config file number is wrong!!"
-
exit 3
-
fi
-
fi
-
-
done<"$CSV_FILE"
-
}
-
#choice
-
cat<<EOF
-
select num:
-
1.create xshell;
-
2.create Base Config;
-
3.exit
-
EOF
-
#
-
read -p "please select num:" answer
-
case $answer in
-
1)
-
create_xshell
-
;;
-
2)
-
create_base_config
-
;;
-
3)
-
exit
-
;;
-
*)
-
echo "please enter:[1|2|3]"
-
;;
-
esac
create_xshell.csv内容如下:
#2001
|
hostname
|
192.168.1.1
|
192.168.1.2
|
192.168.1.3
|
192.168.1.4
|
192.168.1.5
|
192.168.1.6
|
192.168.1.7
|
2
|
10001
|
#2002
|
hostname
|
192.168.2.1
|
192.168.2.2
|
192.168.2.3
|
192.168.2.4
|
192.168.2.5
|
192.168.2.6
|
192.168.2.7
|
2
|
10002
|
#3001
|
hostname
|
192.168.3.1
|
192.168.3.2
|
192.168.3.3
|
192.168.3.4
|
192.168.3.5
|
192.168.3.6
|
192.168.3.7
|
2
|
10003
|
#3002
|
hostname
|
192.168.4.1
|
192.168.4.2
|
192.168.4.3
|
192.168.4.4
|
192.168.4.5
|
192.168.4.6
|
192.168.4.7
|
2
|
10004
|
#2001
|
hostname
|
192.168.5.1
|
192.168.5.2
|
192.168.5.3
|
192.168.5.4
|
192.168.5.5
|
192.168.5.6
|
192.168.5.7
|
2
|
10005
|
阅读(4852) | 评论(0) | 转发(0) |