#!/bin/sh
target_port="......."
cur_usr=`whoami`
#4399 3
#91wan 3
IP_LIST="113........
61.......
113......"
file_name=""
server_count=0
OPR_SCP="false"
OPR_STOP="false"
OPR_RESTART="false"
OPR_DBOPR="false"
DIR=""
usage () {
cat <<EOF
Usage: $0 [OPTIONS]
--scp --dir=filename scp file to all server
--stop stop all server
--dbopr --dir=filename do db opr to all server
--restart --dir=filename restart all server in file
--help Print this message
EOF
exit 1
}
parse_arguments() {
for arg do //for arg in [list] 在for循环中,如果忽略list的话,将会使循环操作$@(命令行参数列表),即以$@作为list
case "$arg" in
--dir=*) DIR=`echo "$arg" | sed -e "s;--dir=;;"` ;;
--scp) OPR_SCP="true";;
--stop) OPR_STOP="true";;
--dbopr) OPR_DBOPR="true";;
--restart) OPR_RESTART="true";;
--help) usage ;;
"") usage ;;
esac
done
}
scp_allserver(){
for line in `echo $IP_LIST`
do
server_count=`expr $server_count + 1`
scp -P$target_port $file_name $cur_usr@$line:/home/$cur_usr/server
if [ ! $? -eq 0 ]; then
echo "*********scp to "$line" fail************"
exit 1
fi
echo "**********scp to "$line" ok**************"
if [ ${file_name:(-3)} == "tgz" ] || [ ${file_name:(-3)} == "tar" ] ; then
ssh -p$target_port $cur_usr@$line "cd /home/$cur_usr/server && tar zxf $file_name"
fi
echo "server_count="$server_count
done
read -p "scp synclist.txt ?[y/n] " confirm
if [ ! $confirm == "y" ] ;then
exit 1
fi
for line in `echo $IP_LIST`
do
scp -P$target_port ./tools/logsync/synclist.txt $cur_usr@$line:/data/logs/ming3
done
}
restart_allserver(){
for line in `echo $IP_LIST`
do
server_count=`expr $server_count + 1`
ssh -p$target_port root@$line "cd /home/$cur_usr/server/$file_name && ./m3ctl.sh restart" &
if [ ! $? -eq 0 ]; then
echo "*********restart "$line" fail***********"
exit 1
fi
echo "**********restart "$line" ok(server count "$server_count ")"
done
}
stop_allserver(){
for line in `echo $IP_LIST`
do
server_count=`expr $server_count + 1`
ssh -p$target_port root@$line "cd /home/$cur_usr/server && ./m3ctl.sh stop" &
if [ ! $? -eq 0 ]; then
echo "*********stop "$line" fail***********"
exit 1
fi
echo "**********stop "$line" ok(server count "$server_count")"
done
}
dbopr_allserver(){
for line in `echo $IP_LIST`
do
server_count=`expr $server_count + 1`
ssh -p$target_port root@$line "cd /home/$cur_usr/server/$file_name && ./DBOpr.sh"
if [ ! $? -eq 0 ]; then
echo "*********dbopr "$line" fail***********"
exit 1
fi
echo "**********dbopr "$line" ok(server count "$server_count")"
done
}
parse_arguments "$@"
if [ $OPR_SCP == "false" -a $OPR_STOP == "false" -a $OPR_RESTART == "false" -a $OPR_DBOPR == "false" ]; then
usage;
exit 1;
fi
if [ $OPR_SCP == "true" -a "$DIR" == "" ] || [ $OPR_RESTART == "true" -a "$DIR" == "" ] || [ $OPR_DBOPR == "true" -a "$DIR" == "" ]; then #note DIR ""
echo "*************need dir name:arg --dir=****************";
exit 1;
fi
if [ $OPR_SCP == "true" -o $OPR_RESTART == "true" -o $OPR_DBOPR == "true" ]; then
if [ ! -f "$DIR" ] && [ ! -d "$DIR" ]; then
echo "------file "$DIR "not exist-----"
exit 1;
fi
file_name=$DIR;
echo "filenam="$file_name;
if [ $OPR_SCP == "true" ]; then
scp_allserver;
elif [ $OPR_DBOPR == "true" ]; then
dbopr_allserver;
else
restart_allserver;
fi
else
stop_allserver;
fi
wait
target_port="......."
cur_usr=`whoami`
#4399 3
#91wan 3
IP_LIST="113........
61.......
113......"
file_name=""
server_count=0
OPR_SCP="false"
OPR_STOP="false"
OPR_RESTART="false"
OPR_DBOPR="false"
DIR=""
usage () {
cat <<EOF
Usage: $0 [OPTIONS]
--scp --dir=filename scp file to all server
--stop stop all server
--dbopr --dir=filename do db opr to all server
--restart --dir=filename restart all server in file
--help Print this message
EOF
exit 1
}
parse_arguments() {
for arg do //for arg in [list] 在for循环中,如果忽略list的话,将会使循环操作$@(命令行参数列表),即以$@作为list
case "$arg" in
--dir=*) DIR=`echo "$arg" | sed -e "s;--dir=;;"` ;;
--scp) OPR_SCP="true";;
--stop) OPR_STOP="true";;
--dbopr) OPR_DBOPR="true";;
--restart) OPR_RESTART="true";;
--help) usage ;;
"") usage ;;
esac
done
}
scp_allserver(){
for line in `echo $IP_LIST`
do
server_count=`expr $server_count + 1`
scp -P$target_port $file_name $cur_usr@$line:/home/$cur_usr/server
if [ ! $? -eq 0 ]; then
echo "*********scp to "$line" fail************"
exit 1
fi
echo "**********scp to "$line" ok**************"
if [ ${file_name:(-3)} == "tgz" ] || [ ${file_name:(-3)} == "tar" ] ; then
ssh -p$target_port $cur_usr@$line "cd /home/$cur_usr/server && tar zxf $file_name"
fi
echo "server_count="$server_count
done
read -p "scp synclist.txt ?[y/n] " confirm
if [ ! $confirm == "y" ] ;then
exit 1
fi
for line in `echo $IP_LIST`
do
scp -P$target_port ./tools/logsync/synclist.txt $cur_usr@$line:/data/logs/ming3
done
}
restart_allserver(){
for line in `echo $IP_LIST`
do
server_count=`expr $server_count + 1`
ssh -p$target_port root@$line "cd /home/$cur_usr/server/$file_name && ./m3ctl.sh restart" &
if [ ! $? -eq 0 ]; then
echo "*********restart "$line" fail***********"
exit 1
fi
echo "**********restart "$line" ok(server count "$server_count ")"
done
}
stop_allserver(){
for line in `echo $IP_LIST`
do
server_count=`expr $server_count + 1`
ssh -p$target_port root@$line "cd /home/$cur_usr/server && ./m3ctl.sh stop" &
if [ ! $? -eq 0 ]; then
echo "*********stop "$line" fail***********"
exit 1
fi
echo "**********stop "$line" ok(server count "$server_count")"
done
}
dbopr_allserver(){
for line in `echo $IP_LIST`
do
server_count=`expr $server_count + 1`
ssh -p$target_port root@$line "cd /home/$cur_usr/server/$file_name && ./DBOpr.sh"
if [ ! $? -eq 0 ]; then
echo "*********dbopr "$line" fail***********"
exit 1
fi
echo "**********dbopr "$line" ok(server count "$server_count")"
done
}
parse_arguments "$@"
if [ $OPR_SCP == "false" -a $OPR_STOP == "false" -a $OPR_RESTART == "false" -a $OPR_DBOPR == "false" ]; then
usage;
exit 1;
fi
if [ $OPR_SCP == "true" -a "$DIR" == "" ] || [ $OPR_RESTART == "true" -a "$DIR" == "" ] || [ $OPR_DBOPR == "true" -a "$DIR" == "" ]; then #note DIR ""
echo "*************need dir name:arg --dir=****************";
exit 1;
fi
if [ $OPR_SCP == "true" -o $OPR_RESTART == "true" -o $OPR_DBOPR == "true" ]; then
if [ ! -f "$DIR" ] && [ ! -d "$DIR" ]; then
echo "------file "$DIR "not exist-----"
exit 1;
fi
file_name=$DIR;
echo "filenam="$file_name;
if [ $OPR_SCP == "true" ]; then
scp_allserver;
elif [ $OPR_DBOPR == "true" ]; then
dbopr_allserver;
else
restart_allserver;
fi
else
stop_allserver;
fi
wait