#!/bin/bash
#op2(132)
server1='http://132.121.97.178:9518/sync/'
#192
server2='http://192.168.51.191:9518/sync/'
#172
server3='http://172.20.3.219:9518/sync/'
now_server=''
server_json=''
dir_temp='/data/mondev/mondo/client/'
log_dir='/data/mondev/mondo/client/log/'
#get current server
getCurrentServer(){
result1=`curl --connect-timeout 2 $server1`
if [ "$?" == "0" ] && [ "$result1" != "" ]
then
now_server=$server1
server_json=$result1
else
result2=`curl --connect-timeout 2 $server2`
if [ "$?" == "0" ] && [ "$result2" != "" ]
then
now_server=$server2
server_json=$result2
else
result3=`curl --connect-timeout 2 $server3`
if [ "$?" == "0" ] && [ "$result3" != "" ]
then
now_server=$server3
server_json=$result3
else
echo "curl: couldn't connect to server host........"
exit 1
fi
fi
fi
}
#mkdir
makeMulitDir(){
err1=`mkdir -p $dir_temp`
if [ "$?" != "0" ] || [ ! -d "$dir_temp" ]
then
echo "mkdir $dir_temp fail............"
exit 1
fi
mkdir -p $log_dir
}
#get file md5
getMd5(){
file_path=$1
file_md5_value=`md5sum $file_path |awk '{print $1}'`
if [ "$?" != "0" ]
then
echo "get file md5 value has error....... $file_path"
file_md5_value=''
fi
}
#downlaod file
downLoadFile(){
temp_url=$1
down_path1=$2
down_path2=$2".temp"
echo "downloading $down_path1"
msg=`curl $temp_url > $down_path2`
if [ "$?" == "0" ]
then
#chekc md5
if [ -f "$down_path2" ]
then
getMd5 $down_path2
if [ "$file_md5_value" == "$md5val" ]
then
# update file suffix
mv $down_path2 $down_path1
else
echo "downloading file $down_path2 has error............"
fi
else
echo "downloading file $temp_url has error............"
fi
else
echo "downloading file $temp_url has error............"
fi
}
#restart mondo
#proc_count="ps -ef|grep magent | grep mondev |grep -v grep|wc -l"
#kill_proc="ps -ef|grep magent|grep mondev | grep -v grep|awk '{print $2}'|xargs kill"
start_script="sh /data/mondev/mondo/client/bin/magent restart"
#kill has exit process
killExitProcess(){
msg2=`ps -ef|grep magent | grep mondev |grep -v grep|wc -l`
if [ "$?" == "0" ] && [ "$msg2" != "" ]
then
count1=`echo $msg2| tr -s " "`
if [ "$count1" != "0" ]
then
msg3=`ps -ef|grep magent|grep mondev | grep -v grep|awk '{print $2}'|xargs kill`
sleep 2
fi
fi
}
#restart
restart(){
echo "begion to restart magent..........."
killExitProcess
sh /data/mondev/mondo/client/bin/magent restart
}
getCurrentServer
makeMulitDir
if [ "$now_server" != "" ] && [ "$server_json" != "" ]
then
echo $now_server
echo $server_json | awk -F[\}] '{for(i=1;i<=NF;i++)if($i!=""&&$i!=" ") print$i}' |while read var
do
#echo $var |tr -d ', :{}'|awk -F\" '{print $2,$6}'
keyval=`echo $var |tr -d ', :{}'|awk -F\" '{print $2}'`
md5val=`echo $var |tr -d ', :{}'|awk -F\" '{print $6}'`
filedir=${keyval%/*}
filename=${keyval##*/}
current_dir=''
if [ "$filedir" != "" ]
then
current_dir="${dir_temp}""${filedir}"
else
current_dir="${dir_temp}"
fi
if [ ! -d "$current_dir" ]
then
mkdir -p $current_dir
fi
current_file="${dir_temp}""${keyval}"
echo "downloading file $current_file"
urltemp="${now_server}""${keyval}"
if [ -f "$current_file" ]
then
#check md5
getMd5 $current_file
if [ "$file_md5_value" != "$md5val" ]
then
#download file
downLoadFile $urltemp $current_file
fi
else
#download file
downLoadFile $urltemp $current_file
fi
sleep 1
done
#chmod +x
chmod -R +x /data/mondev/mondo/client/bin/
chmod -R +x /data/mondev/mondo/client/sh/
restart
else
echo "has error when get server_json..........."
fi
@dianxinguangchang.43F.zhongshanerlu.yuexiuqu.guangzhoushi.guangdongsheng
2016-10-24 17:49
#op2(132)
server1='http://132.121.97.178:9518/sync/'
#192
server2='http://192.168.51.191:9518/sync/'
#172
server3='http://172.20.3.219:9518/sync/'
now_server=''
server_json=''
dir_temp='/data/mondev/mondo/client/'
log_dir='/data/mondev/mondo/client/log/'
#get current server
getCurrentServer(){
result1=`curl --connect-timeout 2 $server1`
if [ "$?" == "0" ] && [ "$result1" != "" ]
then
now_server=$server1
server_json=$result1
else
result2=`curl --connect-timeout 2 $server2`
if [ "$?" == "0" ] && [ "$result2" != "" ]
then
now_server=$server2
server_json=$result2
else
result3=`curl --connect-timeout 2 $server3`
if [ "$?" == "0" ] && [ "$result3" != "" ]
then
now_server=$server3
server_json=$result3
else
echo "curl: couldn't connect to server host........"
exit 1
fi
fi
fi
}
#mkdir
makeMulitDir(){
err1=`mkdir -p $dir_temp`
if [ "$?" != "0" ] || [ ! -d "$dir_temp" ]
then
echo "mkdir $dir_temp fail............"
exit 1
fi
mkdir -p $log_dir
}
#get file md5
getMd5(){
file_path=$1
file_md5_value=`md5sum $file_path |awk '{print $1}'`
if [ "$?" != "0" ]
then
echo "get file md5 value has error....... $file_path"
file_md5_value=''
fi
}
#downlaod file
downLoadFile(){
temp_url=$1
down_path1=$2
down_path2=$2".temp"
echo "downloading $down_path1"
msg=`curl $temp_url > $down_path2`
if [ "$?" == "0" ]
then
#chekc md5
if [ -f "$down_path2" ]
then
getMd5 $down_path2
if [ "$file_md5_value" == "$md5val" ]
then
# update file suffix
mv $down_path2 $down_path1
else
echo "downloading file $down_path2 has error............"
fi
else
echo "downloading file $temp_url has error............"
fi
else
echo "downloading file $temp_url has error............"
fi
}
#restart mondo
#proc_count="ps -ef|grep magent | grep mondev |grep -v grep|wc -l"
#kill_proc="ps -ef|grep magent|grep mondev | grep -v grep|awk '{print $2}'|xargs kill"
start_script="sh /data/mondev/mondo/client/bin/magent restart"
#kill has exit process
killExitProcess(){
msg2=`ps -ef|grep magent | grep mondev |grep -v grep|wc -l`
if [ "$?" == "0" ] && [ "$msg2" != "" ]
then
count1=`echo $msg2| tr -s " "`
if [ "$count1" != "0" ]
then
msg3=`ps -ef|grep magent|grep mondev | grep -v grep|awk '{print $2}'|xargs kill`
sleep 2
fi
fi
}
#restart
restart(){
echo "begion to restart magent..........."
killExitProcess
sh /data/mondev/mondo/client/bin/magent restart
}
getCurrentServer
makeMulitDir
if [ "$now_server" != "" ] && [ "$server_json" != "" ]
then
echo $now_server
echo $server_json | awk -F[\}] '{for(i=1;i<=NF;i++)if($i!=""&&$i!=" ") print$i}' |while read var
do
#echo $var |tr -d ', :{}'|awk -F\" '{print $2,$6}'
keyval=`echo $var |tr -d ', :{}'|awk -F\" '{print $2}'`
md5val=`echo $var |tr -d ', :{}'|awk -F\" '{print $6}'`
filedir=${keyval%/*}
filename=${keyval##*/}
current_dir=''
if [ "$filedir" != "" ]
then
current_dir="${dir_temp}""${filedir}"
else
current_dir="${dir_temp}"
fi
if [ ! -d "$current_dir" ]
then
mkdir -p $current_dir
fi
current_file="${dir_temp}""${keyval}"
echo "downloading file $current_file"
urltemp="${now_server}""${keyval}"
if [ -f "$current_file" ]
then
#check md5
getMd5 $current_file
if [ "$file_md5_value" != "$md5val" ]
then
#download file
downLoadFile $urltemp $current_file
fi
else
#download file
downLoadFile $urltemp $current_file
fi
sleep 1
done
#chmod +x
chmod -R +x /data/mondev/mondo/client/bin/
chmod -R +x /data/mondev/mondo/client/sh/
restart
else
echo "has error when get server_json..........."
fi
@dianxinguangchang.43F.zhongshanerlu.yuexiuqu.guangzhoushi.guangdongsheng
2016-10-24 17:49