1,主机信息表,创建$HOEM/etc/hosts.conf 配置文件
环境 =别名|IP地址 |用户名 |密码
produce=dm1|111.126.147.133|dmzweb|dmzweb
produce=dm2|111.126.147.134|dmzweb|dmzweb
produce=dm3|111.126.181.33|dmzapp|dmzapp
produce=dm4|111.126.181.34|dmzapp|dmzapp
produce=gw1|111.126.212.43|gwtssvc|gwtssvc
produce=gw2|111.126.212.44|gwtssvc|gwtssvc
produce=gw3|111.126.212.45|gwtssvc|gwtssvc
produce=gw4|111.126.212.46|gwtssvc|gwtssvc
produce=gw1|111.126.212.235|gwcusvc|gwcusvc
produce=gw2|111.126.212.236|gwcusvc|gwcusvc
2,免输入密码SSH登陆工具,$HOME/sbin/expect_ssh
#!/bin/expect
set timeout 2
set host [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set cmd [lindex $argv 3]
spawn ssh -l $username $host
expect {
"(yes/no)?" {send "yes\n"}
"*assword:" {send "$password\n"}
}
expect "$username*" {send "$cmd\n"}
#expect "$username*" {send "mv $dest_dir/$src_file bak/`date +%Y%m%d`/$dest_dir/$src_file.`date +%Y%m%d%H%M%S`\n"}
expect "$username*" {send "exit\n"}
expect eof
3,免输入密码传文件工具,$HOME/sbin/expect_scp
#!/bin/expect
set host [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set src_file [lindex $argv 3]
set dest_dir [lindex $argv 4]
set cmd [lindex $argv 5]
spawn scp -P 22 -r $src_file $username@$host:$dest_dir/authorized_keys
expect {
"(yes/no)?" {
send "yes\n"
expect "*assword:" {send "$password\n"}
}
"*assword:" {
send "$password\n"
}
}
expect "100%"
expect eof
4,一键批量免输入密码执行命令或者传文件工具$HOME/sbin/ssh_key.sh
#!/bin/bash
DATE=`date +%Y%m%d%H%M%S`
ip_user=`cat $HOME/etc/hosts.conf | grep -v ^#`
public_keyfile=$HOME/.ssh/id_rsa.pub
export PATH=$PATH:$HOME/.local/bin:$HOME/bin:$HOME/expect/bin/
authorized_keyfile=$HOME/.ssh/authorized_keys
chmod 600 $authorized_keyfile
PUBLIC_KEY=`cat $public_keyfile`
KEYFILE_DIFF=`grep -w "$PUBLIC_KEY" $authorized_keyfile | grep -v grep |wc -l`
if [ $KEYFILE_DIFF == 0 ]
then
echo "新密钥"
echo $PUBLIC_KEY >> $authorized_keyfile
sleep 5
else
echo "密钥已存在"
sleep 5
fi
for for_user in $ip_user
do
if [ "$1" == "cmd" ]
then
$HOME/sbin/expect_ssh $ip $user $pass "$2"
fi
if [ "$1" == "scp" ]
then
$HOME/sbin/expect_scp $ip $user $pass $authorized_keyfile ".ssh"
fi
done
wait
5,首次批量上传linux服务ssh互信秘钥文件 authorized_keys
sh $HOEM/sbin/ssh_key.sh scp
6,批量维护脚本,$HOME/sbin/deploy
#!/bin/bash
#set -x
#ip:username:password
if [ "$#" -eq 0 ]
then
echo "################################################################"
echo "# deploy server restart|start|stop|status all|username nodes|node1|node2|node3|node4 所有服务#"
echo "# deploy server start all nodes1 启动一半服务器 #"
echo "#--------------------------------------------------------------#"
echo "# deploy cmd all|node "command" 批量执行命令#"
echo "#--------------------------------------------------------------#"
echo "# deploy filename romte_dir all 上传文件 #"
echo "#--------------------------------------------------------------#"
echo "# deploy redis restart|start|stop|status redis服务#"
echo "#**#"
exit 1
fi
port=22
src_file=$1
dest_dir=$2
#文件传输
if [ -f $src_file ]
then
#list=cat $HOME/etc/hosxxxx.conf | grep -w produce | grep -E "ps|bi|bs|ci|sr|pm|rpt|his"
list=cat $HOME/etc/hosxxxx.conf | grep -w produce | grep -v ^#
if [ "$4" == pgdb ]
then
list=cat $HOME/etc/hosxxxx.conf | grep -w pgdb | grep -v ^#
fi
for i in $list
do
hostid=`echo $i| awk -F"=" '{print $2}' | awk -F"|" '{print $1}'`
host=`echo $i | awk -F"=" '{print $2}' | awk -F"|" '{print $2}'`
if [ "$USER" == appview ]
then
username=appview
else
username=`echo $i | awk -F"=" '{print $2}' | awk -F"|" '{print $3}'`
fi
password=`echo $i | awk -F"=" '{print $2}' | awk -F"|" '{print $4}'`
PLAT_CD=`echo $i | awk -F"=" '{print $2}' | awk -F"|" '{print $3}'`
if [ "$3" == "$PLAT_CD" ]
then
if [ "A$4" == "A" -o "$4" == "$hostid" ]
then
echo ""
else
continue
fi
if [ "$username" == "ybxxxxsvc" ]
then
username=xxxxsvc
fi
if [ "$username" == "inxxxxvc" ]
then
username=xxxxsvc
fi
echo "------------$username-$hostid-$hostid-$host-$dest_dir-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "mkdir -p bak/$dest_dir/`date +%Y%m%d`"
ssh -o "StrictHostKeyChecking no" $username@$host "mv $dest_dir/$src_file bak/$dest_dir/`date +%Y%m%d`/$src_file.`date +%Y%m%d%H%M%S`"
scp -P $port -r $src_file $username@$host:$dest_dir
echo ""
echo "**************************************************"
echo ""
fi
if [ "$3" == "all" ]
then
if [ ! "$username" == "intxxxxx" ]
then
if [ "$username" == "ybxxxxsvc" ]
then
username=xxxxsvc
fi
if [ "$username" == "inxxxxvc" ]
then
username=xxxxsvc
fi
echo "------------$username-$hostid-$hostid-$host-$dest_dir-------------"
echo ""
#ssh -o "StrictHostKeyChecking no" $username@$host "mkdir -p bak/`date +%Y%m%d`/$dest_dir"
#ssh -o "StrictHostKeyChecking no" $username@$host "mv $dest_dir/$src_file bak/`date +%Y%m%d`/$dest_dir/$src_file.`date +%Y%m%d%H%M%S`"
ssh -o "StrictHostKeyChecking no" $username@$host "mkdir -p bak/$dest_dir/`date +%Y%m%d`"
ssh -o "StrictHostKeyChecking no" $username@$host "mv $dest_dir/$src_file bak/$dest_dir/`date +%Y%m%d`/$src_file.`date +%Y%m%d%H%M%S`"
scp -P $port -r $src_file $username@$host:$dest_dir
echo ""
echo "**************************************************"
echo ""
fi
fi
done
fi
#远程执行服务器命令
if [ "$1" == "cmd" ]
then
if [ -z "$2" ]
then
echo "deploy cmd ["CMD"] [sys_user]------缺少参数"
exit 1
fi
if [ -z "$3" ]
then
echo "deploy cmd ["CMD"] [sys_user]------缺少参数"
exit 1
fi
#list=`cat $HOME/etc/hosxxxx.conf | grep -w produce | grep -E "ps|bi|bs|ci|sr|pm|rpt|his"`
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -v ^# | grep -v ^$`
if [ "$4" == pgdb ]
then
list=cat $HOME/etc/hosxxxx.conf | grep -w pgdb | grep -v ^#
fi
cmd="$2"
#cmd_para=`echo $cmd | grep -w rm`
cmd_para=`echo $cmd | grep -w aaaa`
if [ -z "$cmd_para" ]
then
for CMDD in $list
do
hostid=`echo $CMDD | awk -F"=" '{print $2}' | awk -F"|" '{print $1}'`
host=`echo $CMDD | awk -F"=" '{print $2}' | awk -F"|" '{print $2}'`
if [ "$USER" == appview ]
then
username=appview
else
username=`echo $CMDD | awk -F"=" '{print $2}' | awk -F"|" '{print $3}'`
fi
password=`echo $CMDD | awk -F"=" '{print $2}' | awk -F"|" '{print $4}'`
PLAT_CD=`echo $CMDD | awk -F"=" '{print $2}' | awk -F"|" '{print $3}'`
#$HOME/sbin/expect_ssh $host $port $username $password "$cmd"
if [ "$3" == "$PLAT_CD" ]
then
if [ "A$4" == "A" -o "$4" == "$hostid" ]
then
echo ""
else
continue
fi
if [ "$username" == "ybxxxxsvc" ]
then
username=xxxxsvc
fi
if [ "$username" == "inxxxxvc" ]
then
username=xxxxsvc
fi
echo "------------$username-$hostid-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd"
echo ""
echo "**************************************************"
echo ""
fi
if [ "$3" == "all" -o "A"$3 == "A" ]
then
if [ "$username" == "ybxxxxsvc" ]
then
username=xxxxsvc
fi
if [ "$username" == "inxxxxvc" ]
then
username=xxxxsvc
fi
echo "------------$username-$hostid-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd"
echo ""
echo "**************************************************"
echo ""
fi
done
else
echo "You can't use the rm command : $cmd"
fi
fi
##服务重启
if [ "$1" == "server" ]
then
if [ "$2" == "stop" ]
then
STAT=0
fi
if [ "$2" == "start" ]
then
STAT=1
fi
if [ ! -z "$3" ]
then
if [ -z "$4" ]
then
echo "Usage: {nodes|node1|node2|node3|node4}"
exit 1
fi
fi
NODES_PARA=`cat $HOME/etc/hosxxxx.conf | grep -w nodes_para |awk -F"=" '{print $2}'`
if [ "$NODES_PARA" == "HF" ]
then
NODES="\-01|\-02|\-03|\-04"
NODE1="\-01"
NODE2="\-02"
NODE3="\-03"
NODE4="\-04"
NODES1="\-01|\-03"
NODES2="\-02|\-04"
fi
if [ "$NODES_PARA" == "YZ" ]
then
NODES="\-11|\-12|\-13|\-14"
NODE1="\-11"
NODE2="\-12"
NODE3="\-13"
NODE4="\-14"
NODES1="\-11|\-13"
NODES2="\-12|\-14"
fi
if [ "$4" == "nodes" ]
then
if [ "$3" == "all" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" | grep -E "$NODES"`
else
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" | grep -E "$NODES" | grep $3`
fi
if [ "$3" == "pswsl" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" | grep -E "$NODES" | grep PS`
fi
if [ "$3" == "cidaemon" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" | grep -E "$NODES" | grep CI`
fi
if [ "$3" == "daemon" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|sr|pm|rpt|his" | grep -E "$NODES" `
fi
fi
if [ "$4" == "nodes1" ]
then
if [ "$3" == "all" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" | grep -E "$NODES1"`
else
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" |grep $3 | grep -E "$NODES1"`
fi
if [ "$3" == "pswsl" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" | grep PS | grep -E "$NODES1"`
fi
if [ "$3" == "cidaemon" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" | grep CI | grep -E "$NODES1"`
fi
if [ "$3" == "daemon" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|sr|pm|rpt|his" |grep -E "$NODES1"`
fi
fi
if [ "$4" == "nodes2" ]
then
if [ "$3" == "all" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" | grep -E "$NODES2"`
else
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" |grep $3 | grep -E "$NODES2"`
fi
if [ "$3" == "pswsl" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" | grep PS | grep -E "$NODES2"`
fi
if [ "$3" == "cidaemon" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" | grep CI | grep -E "$NODES2"`
fi
if [ "$3" == "daemon" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|sr|pm|rpt|his" | grep -E "$NODES2"`
fi
fi
if [ "$4" == "node1" ]
then
if [ "$3" == "all" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" | grep "$NODE1"`
else
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" |grep $3 | grep "$NODE1"`
fi
if [ "$3" == "pswsl" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" | grep PS | grep "$NODE1"`
fi
if [ "$3" == "cidaemon" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" | grep CI | grep "$NODE1"`
fi
if [ "$3" == "daemon" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|sr|pm|rpt|his" | grep "$NODE1"`
fi
fi
if [ "$4" == "node2" ]
then
if [ "$3" == "all" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" | grep "$NODE2"`
else
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" |grep $3 | grep "$NODE2"`
fi
if [ "$3" == "pswsl" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" | grep PS | grep "$NODE2"`
fi
if [ "$3" == "cidaemon" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" | grep CI | grep "$NODE2"`
fi
if [ "$3" == "daemon" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|sr|pm|rpt|his" | grep "$NODE2"`
fi
fi
if [ "$4" == "node3" ]
then
if [ "$3" == "all" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" | grep "$NODE3"`
else
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" |grep $3 | grep "$NODE3"`
fi
if [ "$3" == "pswsl" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" | grep PS | grep "$NODE3"`
fi
if [ "$3" == "cidaemon" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" | grep CI | grep "$NODE3"`
fi
if [ "$3" == "daemon" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|sr|pm|rpt|his" | grep "$NODE3"`
fi
fi
if [ "$4" == "node4" ]
then
if [ "$3" == "all" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" | grep "$NODE4"`
else
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" |grep $3 | grep "$NODE4"`
fi
if [ "$3" == "pswsl" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" | grep PS | grep "$NODE4"`
fi
if [ "$3" == "cidaemon" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|ci|sr|pm|rpt|his" | grep CI | grep "$NODE4"`
fi
if [ "$3" == "daemon" ]
then
list=`cat $HOME/etc/hosxxxx.conf | grep -w produce |grep -E "ps|bi|bs|sr|pm|rpt|his" | grep "$NODE4"`
fi
fi
case "$2" in
start)
case "$3" in
srxxxxx)
for HOST_LIST in $list
do
PLAT_CD=SR
Route_Conf 2
if [ ! -z $host ]
then
cmd="services_node start"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
fi
done
wait
if [ ! "$5" == "all" ]
then
Route_Conf $STAT
fi
;;
bixxxxx)
for HOST_LIST in $list
do
PLAT_CD=BI
Route_Conf 2
if [ ! -z $host ]
then
cmd="services_node start"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
fi
done
wait
if [ ! "$5" == "all" ]
then
Route_Conf $STAT
fi
;;
bsxxxxx)
for HOST_LIST in $list
do
PLAT_CD=BS
Route_Conf 2
if [ ! -z $host ]
then
cmd="services_node start"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
fi
done
wait
if [ ! "$5" == "all" ]
then
Route_Conf $STAT
fi
;;
rptxxxxx)
for HOST_LIST in $list
do
PLAT_CD=RP
Route_Conf 2
if [ ! -z $host ]
then
cmd="services_node start"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
fi
done
wait
if [ ! "$5" == "all" ]
then
Route_Conf $STAT
fi
;;
hisxxxxx)
for HOST_LIST in $list
do
PLAT_CD=HI
Route_Conf 2
if [ ! -z $host ]
then
cmd="services_node start"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
fi
done
wait
if [ ! "$5" == "all" ]
then
Route_Conf $STAT
fi
;;
cixxxxx)
for HOST_LIST in $list
do
PLAT_CD=CI
Route_Conf 2
if [ ! -z $host ]
then
cmd="services_node start"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
fi
done
wait
if [ ! "$5" == "all" ]
then
Route_Conf $STAT
fi
;;
cidaemon)
for HOST_LIST in $list
do
PLAT_CD=CI
Route_Conf 2
if [ ! -z $host ]
then
cmd="startdaemon.sh"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
fi
done
if [ ! "$5" == "all" ]
then
Route_Conf $STAT
fi
;;
daemon)
for HOST_LIST in $list
do
PLAT_CD=all
Route_Conf 2
if [ ! -z $host ]
then
cmd="startdaemon.sh"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
fi
done
if [ ! "$5" == "all" ]
then
Route_Conf $STAT daemon
fi
;;
pmxxxxx)
for HOST_LIST in $list
do
PLAT_CD=PM
Route_Conf 2
if [ ! -z $host ]
then
cmd="services_node start"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
fi
done
wait
if [ ! "$5" == "all" ]
then
Route_Conf $STAT
fi
;;
psxxxxx)
for HOST_LIST in $list
do
PLAT_CD=PS
Route_Conf 2
if [ ! -z $host ]
then
cmd="services_node start"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
fi
done
wait
if [ ! "$5" == "all" ]
then
Route_Conf $STAT
fi
;;
pswsl)
for HOST_LIST in $list
do
PLAT_CD=PS
Route_Conf 2
if [ ! -z $host ]
then
cmd="tmboot -s WSL"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
fi
done
wait
if [ ! "$5" == "all" ]
then
Route_Conf $STAT
fi
;;
all)
cd "$CMD"
echo "------开始启动cidaemon"
$0 $1 $2 cidaemon $4 all
echo "------启动完毕cidaemon"
$0 $1 $2 srxxxxx $4 all
sleep 2
$0 $1 $2 cixxxxx $4 all
$0 $1 $2 bixxxxx $4 all &
$0 $1 $2 bsxxxxx $4 all &
$0 $1 $2 rptxxxxx $4 all &
$0 $1 $2 hisxxxxx $4 all &
$0 $1 $2 psxxxxx $4 all &
$0 $1 $2 pmxxxxx $4 all &
echo "------开始启动daemon"
$0 $1 $2 daemon $4 all
echo "------启动完毕daemon"
sleep 2
wait
echo "--------开始启动pswsl"
$0 $1 $2 pswsl $4 all
$0 $1 status psxxxxx $4 > /dev/null 2>&1 &
echo "--------服务启动完毕,等待10秒"
sleep 10
Route_Conf $STAT
;;
*)
echo $"Usage: $3 {all|srxxxxx|cidaemon|cixxxxx|bixxxxx|bsxxxxx|rptxxxxx|hisxxxxx|psxxxxx|pmxxxxx|daemon|pswsl}"
exit 2
;;
esac
;;
stop)
if [[ ! "$3" == daemon ]]
then
Route_Conf $STAT
fi
case "$3" in
srxxxxx)
for HOST_LIST in $list
do
PLAT_CD=SR
Route_Conf 2
if [ ! -z $host ]
then
cmd="services_node stop"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
fi
done
wait
;;
bixxxxx)
for HOST_LIST in $list
do
PLAT_CD=BI
Route_Conf 2
if [ ! -z $host ]
then
cmd="services_node stop"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
fi
done
wait
;;
bsxxxxx)
for HOST_LIST in $list
do
PLAT_CD=BS
Route_Conf 2
if [ ! -z $host ]
then
cmd="services_node stop"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
fi
done
wait
;;
rptxxxxx)
for HOST_LIST in $list
do
PLAT_CD=RP
Route_Conf 2
if [ ! -z $host ]
then
cmd="services_node stop"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
fi
done
wait
;;
hisxxxxx)
for HOST_LIST in $list
do
PLAT_CD=HI
Route_Conf 2
if [ ! -z $host ]
then
cmd="services_node stop"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
fi
done
wait
;;
cixxxxx)
for HOST_LIST in $list
do
PLAT_CD=CI
Route_Conf 2
if [ ! -z $host ]
then
cmd="services_node stop"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
fi
done
wait
;;
cidaemon)
for HOST_LIST in $list
do
PLAT_CD=CI
Route_Conf 2
if [ ! -z $host ]
then
cmd="stopdaemon.sh"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
fi
done
wait
;;
daemon)
for HOST_LIST in $list
do
PLAT_CD=all
Route_Conf 2
if [ ! -z $host ]
then
cmd="stopdaemon.sh"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
fi
done
wait
;;
pmxxxxx)
for HOST_LIST in $list
do
PLAT_CD=PM
Route_Conf 2
if [ ! -z $host ]
then
cmd="services_node stop"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
fi
done
wait
;;
psxxxxx)
for HOST_LIST in $list
do
PLAT_CD=PS
Route_Conf 2
if [ ! -z $host ]
then
cmd="services_node stop"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
fi
done
wait
;;
pswsl)
for HOST_LIST in $list
do
PLAT_CD=PS
Route_Conf 2
if [ ! -z $host ]
then
cmd="tmshutdown -s WSL"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
fi
done
wait
;;
all)
cd "$CMD"
echo "--------开始停服务"
$0 $1 $2 pswsl $4
echo "--------pswsl停服务完毕,等到30秒。"
sleep 30
$0 $1 $2 daemon $4
sleep 2
$0 $1 $2 pmxxxxx $4 &
$0 $1 $2 psxxxxx $4 &
$0 $1 $2 hisxxxxx $4 &
$0 $1 $2 rptxxxxx $4 &
$0 $1 $2 bsxxxxx $4 &
$0 $1 $2 bixxxxx $4 &
$0 $1 $2 cixxxxx $4
$0 $1 $2 cidaemon $4
sleep 2
$0 $1 $2 srxxxxx $4
;;
*)
echo $"Usage: $3 {all|srxxxxx|cidaemon|cixxxxx|bixxxxx|bsxxxxx|rptxxxxx|hisxxxxx|psxxxxx|pmxxxxx|daemon|pswsl}"
exit 2
;;
esac
;;
status)
case "$3" in
psxxxxx)
for PS in $list
do
PLAT_CD=ps
host=`echo $PS | grep $PLAT_CD | awk -F"=" '{print $2}' | awk -F"|" '{print $2}'`
username=`echo $PS |grep $PLAT_CD | awk -F"=" '{print $2}' | awk -F"|" '{print $3}'`
password=`echo $PS | grep $PLAT_CD | awk -F"=" '{print $2}' | awk -F"|" '{print $4}'`
if [ ! -z $host ]
then
cmd="services_node status"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd"
echo ""
echo "**************************************************"
echo ""
fi
done
;;
cixxxxx)
for CI in $list
do
PLAT_CD=ci
host=`echo $CI |grep $PLAT_CD | awk -F"=" '{print $2}' | awk -F"|" '{print $2}'`
username=`echo $CI | grep $PLAT_CD | awk -F"=" '{print $2}' | awk -F"|" '{print $3}'`
password=`echo $CI |grep $PLAT_CD | awk -F"=" '{print $2}' | awk -F"|" '{print $4}'`
if [ ! -z $host ]
then
cmd="services_node status"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd"
echo ""
echo "**************************************************"
echo ""
fi
done
;;
bsxxxxx)
for BS in $list
do
PLAT_CD=bs
host=`echo $BS |grep $PLAT_CD | awk -F"=" '{print $2}' | awk -F"|" '{print $2}'`
username=`echo $BS |grep $PLAT_CD | awk -F"=" '{print $2}' | awk -F"|" '{print $3}'`
password=`echo $BS |grep $PLAT_CD | awk -F"=" '{print $2}' | awk -F"|" '{print $4}'`
if [ ! -z $host ]
then
cmd="services_node status"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd"
echo ""
echo "**************************************************"
echo ""
fi
done
;;
bixxxxx)
for BI in $list
do
PLAT_CD=bi
host=`echo $BI | grep $PLAT_CD | awk -F"=" '{print $2}' | awk -F"|" '{print $2}'`
username=`echo $BI | grep $PLAT_CD | awk -F"=" '{print $2}' | awk -F"|" '{print $3}'`
password=`echo $BI | grep $PLAT_CD | awk -F"=" '{print $2}' | awk -F"|" '{print $4}'`
if [ ! -z $host ]
then
cmd="services_node status"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd"
echo ""
echo "**************************************************"
echo ""
fi
done
;;
pmxxxxx)
for PM in $list
do
PLAT_CD=pm
host=`echo $PM |grep $PLAT_CD | awk -F"=" '{print $2}' | awk -F"|" '{print $2}'`
username=`echo $PM |grep $PLAT_CD | awk -F"=" '{print $2}' | awk -F"|" '{print $3}'`
password=`echo $PM |grep $PLAT_CD | awk -F"=" '{print $2}' | awk -F"|" '{print $4}'`
if [ ! -z $host ]
then
cmd="services_node status"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd"
echo ""
echo "**************************************************"
echo ""
fi
done
;;
rptxxxxx)
for RPT in $list
do
PLAT_CD=rpt
host=`echo $RPT |grep $PLAT_CD | awk -F"=" '{print $2}' | awk -F"|" '{print $2}'`
username=`echo $RPT | grep $PLAT_CD | awk -F"=" '{print $2}' | awk -F"|" '{print $3}'`
password=`echo $RPT | grep $PLAT_CD | awk -F"=" '{print $2}' | awk -F"|" '{print $4}'`
if [ ! -z $host ]
then
cmd="services_node status"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd"
echo ""
echo "**************************************************"
echo ""
fi
done
;;
hisxxxxx)
for HIS in $list
do
PLAT_CD=his
host=`echo $HIS | grep $PLAT_CD | awk -F"=" '{print $2}' | awk -F"|" '{print $2}'`
username=`echo $HIS | grep $PLAT_CD | awk -F"=" '{print $2}' | awk -F"|" '{print $3}'`
password=`echo $HIS | grep $PLAT_CD | awk -F"=" '{print $2}' | awk -F"|" '{print $4}'`
if [ ! -z $host ]
then
cmd="services_node status"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd"
echo ""
echo "**************************************************"
echo ""
fi
done
;;
srxxxxx)
for SR in $list
do
PLAT_CD=sr
host=`echo $SR | grep $PLAT_CD | awk -F"=" '{print $2}' | awk -F"|" '{print $2}'`
username=`echo $SR | grep $PLAT_CD | awk -F"=" '{print $2}' | awk -F"|" '{print $3}'`
password=`echo $SR | grep $PLAT_CD | awk -F"=" '{print $2}' | awk -F"|" '{print $4}'`
if [ ! -z $host ]
then
cmd="services_node status"
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd"
echo ""
echo "**************************************************"
echo ""
fi
done
;;
all)
$0 $1 $2 psxxxxx $4
sleep 2
$0 $1 $2 cixxxxx $4
sleep 2
$0 $1 $2 bsxxxxx $4
sleep 2
$0 $1 $2 bixxxxx $4
sleep 2
$0 $1 $2 pmxxxxx $4
sleep 2
$0 $1 $2 rptxxxxx $4
sleep 2
$0 $1 $2 hisxxxxx $4
sleep 2
$0 $1 $2 srxxxxx $4
;;
*)
echo $"Usage: $3 {psxxxxx|cixxxxx|bsxxxxx|bixxxxx|pmxxxxx|rptxxxxx|hisxxxxx|srxxxxx|all}"
exit 2
;;
esac
;;
restart)
cd "$CWD"
$0 stop
$0 start
;;
*)
echo $"Usage: $2 {start|stop|status|restart}"
exit 2
;;
esac
fi
if [ "$1" == "intxxxxx" ]
then
if [ "$1" == "pro" ]
then
intxxxxx_list=cat $HOME/etc/hosxxxx.conf | grep -w produce | grep intxxxxx
fi
if [ "$1" == "ver" ]
then
intxxxxx_list=`cat $HOME/etc/hosxxxx.conf | grep -w ver | grep intxxxxx`
fi
case "$2" in
start)
for intxxxxx in $intxxxxx_list
do
cmd="startall;startdaemon.sh"
host=`echo $intxxxxx | awk -F"=" '{print $2}' | awk -F"|" '{print $2}'`
username=`echo $intxxxxx | awk -F"=" '{print $2}' | awk -F"|" '{print $3}'`
password=`echo $intxxxxx | awk -F"=" '{print $2}' | awk -F"|" '{print $4}'`
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
done
;;
stop)
for intxxxxx in $intxxxxx_list
do
cmd="stopall;stopdaemon.sh"
host=`echo $intxxxxx | awk -F"=" '{print $2}' | awk -F"|" '{print $2}'`
username=`echo $intxxxxx | awk -F"=" '{print $2}' | awk -F"|" '{print $3}'`
password=`echo $intxxxxx | awk -F"=" '{print $2}' | awk -F"|" '{print $4}'`
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
done
;;
status)
for intxxxxx in $intxxxxx_list
do
cmd="inxxxxtatus"
host=`echo $intxxxxx | awk -F"=" '{print $2}' | awk -F"|" '{print $2}'`
username=`echo $intxxxxx | awk -F"=" '{print $2}' | awk -F"|" '{print $3}'`
password=`echo $intxxxxx | awk -F"=" '{print $2}' | awk -F"|" '{print $4}'`
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd"
echo ""
echo "**************************************************"
echo ""
done
;;
restart)
cd "$CWD"
$0 stop
sleep 5
$0 start
;;
*)
echo $"Usage: $2 {start|stop|status|restart}"
exit 2
;;
esac
fi
if [ "$2" == "redis" ]
then
if [ "$1" == "pro" ]
then
redis_list=cat $HOME/etc/hosxxxx.conf | grep -w produce | grep redis
fi
if [ "$1" == "ver" ]
then
redis_list=`cat $HOME/etc/hosxxxx.conf | grep -w ver | grep redis`
fi
case "$3" in
start)
for redis in $redis_list
do
cmd="redis start"
host=`echo $redis | awk -F"=" '{print $2}' | awk -F"|" '{print $2}'`
username=`echo $redis | awk -F"=" '{print $2}' | awk -F"|" '{print $3}'`
password=`echo $redis | awk -F"=" '{print $2}' | awk -F"|" '{print $4}'`
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd" &
echo ""
echo "**************************************************"
echo ""
done
wait
;;
stop)
for redis in $redis_list
do
cmd="redis stop"
host=`echo $redis | awk -F"=" '{print $2}' | awk -F"|" '{print $2}'`
username=`echo $redis | awk -F"=" '{print $2}' | awk -F"|" '{print $3}'`
password=`echo $redis | awk -F"=" '{print $2}' | awk -F"|" '{print $4}'`
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd"
echo ""
echo "**************************************************"
echo ""
done
;;
status)
for redis in $redis_list
do
cmd="redis status"
host=`echo $redis | awk -F"=" '{print $2}' | awk -F"|" '{print $2}'`
username=`echo $redis | awk -F"=" '{print $2}' | awk -F"|" '{print $3}'`
password=`echo $redis | awk -F"=" '{print $2}' | awk -F"|" '{print $4}'`
echo "------------$username-$hostid-$host-------------"
echo ""
ssh -o "StrictHostKeyChecking no" $username@$host "source .bash_profile;$cmd"
echo ""
echo "**************************************************"
echo ""
done
;;
restart)
cd "$CWD"
$0 $1 $2 stop
$0 $1 $2 start all
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 2
;;
esac
fi