-
PHP
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#!/bin/bash
USER_NO=$(
id
|
grep
-P
"richmail|root"
)
if
[[ -z $USER_NO ]] ;
then
echo
" run must in richmail user"
exit
1
fi
TIME=$(
date
"+%Y%m%d%H%M%S"
)
DATE=$(
date
"+%Y-%m-%d"
)
export
PATH=
/bin
:
/bin
:
/usr/kerberos/sbin
:
/usr/kerberos/bin
:
/usr/local/sbin
:
/usr/bin
:
/bin
:
/usr/sbin
:
/sbin
:
/root/bin
:
/usr/local/bin/
:$PATH
export
LD_LIBRARY_PATH=:
/home/richmail/oracle_client/lib
:
/home/richmail/lib
:
/home/richmail/oracle_client/lib
:
/home/richmail/lib
export
RICHMAIL_HOME=
/home/richmail
HOST_CONF=
/home/richmail/newconf/hosts
.conf
HOST_BAK_dir=
/home/scripts/hostconf_bak/
LOGFILE=${HOST_BAK_dir}
/logs/ms_change_packlog
.${DATE}
#HOST_CONF=/tmp/hosts.conf
#HOST_BAK_dir=/tmp/hostconf_bak/
#LOGFILE=${HOST_BAK_dir}/logs/change_packlog.${DATE}
if
[ $
# != 2 ];then
echo
"USAGE:$0 The two parameter"
echo
"USAGE:$0 incoming parameters digit 1 or 3 or 5 or 7:"
echo
"USAGE:$0 all_9qi|[192.168.220.1-38] 3"
exit
1;
fi
IP_MS=$1
PACK_R=$2
if
[[
"$IP_MS"
==
"check"
&&
"$PACK_R"
==
"query"
]];
then
sed
-rn
'/^ip=192.168.220.1/,/cloud-ms-38\/logreport/p'
$HOST_CONF|
awk
'{if($0~/^ip=192.168.220./){if(int(substr($0,16))<=38){printf "%s ",$0;flag=1}};if($1~/pack_thread_num/ && flag==1){printf "%d\n",$3}}'
echo
"end of query"
exit
0
fi
if
[[ ! -d ${HOST_BAK_dir} ]] ;
then
mkdir
-p ${HOST_BAK_dir}
chown
richmail.richmail ${HOST_BAK_dir}
fi
if
[[ ! -d ${HOST_BAK_dir}
/logs
]] ;
then
mkdir
-p ${HOST_BAK_dir}
/logs
chown
richmail.richmail ${HOST_BAK_dir}
/logs
fi
cp
-avpR $HOST_CONF ${HOST_BAK_dir}
/hosts
.conf.${TIME} >> $LOGFILE
chown
richmail.richmail $LOGFILE
if
[[ $? -
ne
0 ]] ;
then
echo
"$TIME cp error, script quit ! "
>> $LOGFILE
exit
1
fi
echo
"$TIME pack_thread change $IP_MS $PACK_R"
>> $LOGFILE
if
[[
"$IP_MS"
==
"all"
]] ;
then
# sed -ri '/^ip=192.168.220.1/,${/\bpack_thread_num\b/{s/ =.*/ = '"$PACK_R"'/g}}' $HOST_CONF
sed
-ri
'/^ip=192.168.220.1/,/cloud-ms-38\/logreport/{/\bpack_thread_num\b/{s/ =.*/ = '
"$PACK_R"
'/g}}'
$HOST_CONF
diff
$HOST_CONF ${HOST_BAK_dir}
/hosts
.conf.${TIME}
# sed -rn '/^ip=192.168.220.1/,${/\bpack_thread_num\b/{s/ =.*/ = '"$PACK_R"'/gp}}' $HOST_CONF >> $LOGFILE
echo
5 |
/home/richmail/bin/confutil
;
echo
0
for
((i=1;i<=38;i++));
do
echo
y |
/home/richmail/bin/richmail
--sys-restart 192.168.220.${i} mssvr >>
/home/scripts/logs/ms_change_pack
.log.${DATE} 2>&1
echo
y |
/home/richmail/bin/richmail
--sys-restart 192.168.220.${i} mssvr
echo
"all: 192.168.220.${i} restart"
done
diff
$HOST_CONF ${HOST_BAK_dir}
/hosts
.conf.${TIME} >> $LOGFILE
#sed -rn '/^ip=192.168.220.1/,${/\bpack_thread_num\b/{s/ =.*/ = '"$PACK_R"'/gp}}' $HOST_CONF >> $LOGFILE
exit
0
else
if
[[ -z $(
echo
$IP_MS|
grep
-P
"^192\.168\.220\.([1-9]|1[0-9]|2[0-9]|3[0-8])$"
) ]];
then
echo
"parameter not right all_9qi|[192.168.220.1-38]"
;
exit
1;
fi
#IP_MS_PLUS="192.168.220."$((${IP_MS##*.}+1))
IP_MS_PLUS=$((${IP_MS
##*.}+1))
echo
"${IP_MS}iiiiii${IP_MS_PLUS}"
sed
-ri
'/^ip=\b'
"${IP_MS}"
'\b$/,/^ip=192.168.220.\b'
${IP_MS_PLUS}
'\b$/{/\bpack_thread_num\b/{s/ =.*/ = '
"$PACK_R"
'/g}}'
$HOST_CONF
diff
$HOST_CONF ${HOST_BAK_dir}
/hosts
.conf.${TIME}
echo
5 |
/home/richmail/bin/confutil
;
echo
0
echo
y |
/home/richmail/bin/richmail
--sys-restart $IP_MS mssvr
echo
"restart ${IP_MS}"
diff
$HOST_CONF ${HOST_BAK_dir}
/hosts
.conf.${TIME} >> $LOGFILE
exit
0
fi
|
<?php
date_default_timezone_set(
"PRC"
);
require
(dirname(
__FILE__
).
'/../../config/config.php'
);
$md5_from_user
=MD5(
$_SERVER
[
'REMOTE_ADDR'
].
$_COOKIE
[
'uname'
].
$cookie_token
);
if
(
$_COOKIE
[
'userip'
] !=
"$md5_from_user"
){
setcookie(
"uname"
,NULL);
setcookie(
"userip"
,NULL);
header(
"Status: 302 Moved Temporaly"
,true,302);
echo
"<script language=javascript>window.parent.location='/kcgi-bin/publish/index.php';</script>"
;
exit
;
}
function
log_write_file(
$user
,
$user_ip
,
$sel_ip
=
"none"
,
$pack_right
=
"none"
){
try
{
$timenow
=
date
(
"Y-m-d H:i:s"
,time());
$daynow
=
date
(
"Y-m-d"
,time());
$fhandle
=
fopen
(
"logs/operation_pack_right.log.$daynow"
,
"a"
);
fwrite(
$fhandle
,
$timenow
.
"|"
.
$user
.
"|"
.
$user_ip
.
"|"
.
$sel_ip
.
"|"
.
$pack_right
.
"\n"
);
fflush
(
$fhandle
);
fclose(
$fhandle
);
}
catch
(exception
$e
){
echo
$e
;
}
return
0;
}
?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<html xmlns=
"http://www.w3.org/1999/xhtml"
>
<head>
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
/>
<title>打包权重</title>
<style type=
"text/css"
>
<!--
#Layer1 {
position:absolute;
width:200px;
height:115px;
z-index:1;
left: 13px;
top: 164px;
}
-->
</style>
</head>
<script type=
"text/javascript"
>
function
load_select_ip(){
var
svr_slt_node=document.getElementById(
"sel_ip"
);
for
(
var
i=0;i<=38;i++) {
var
sel=document.createElement(
"option"
);
if
( i== 0 ){tmp_trim=
"all"
}
else
{
var
tmp_trim=
"192.168.220."
+i;
}
var
newText=document.createTextNode(tmp_trim);
sel.appendChild(newText);
sel.setAttribute(
"value"
,tmp_trim);
svr_slt_node.appendChild(sel);
}
}
</script>
<body onload=load_select_ip()>
<div>此处显示新 Div 标签的内容
<form id=
"form1"
name=
"form1"
method=
"post"
action=
"view_pack.php"
>
<table border=
"1"
>
<tr>
<td >IP:
<select name=
"sel_ip"
id=
"sel_ip"
>
</select>
</td>
<td width=
"152"
>打包权重:
<select name=
"pack_right"
id=
"pack_right"
>
<option value=
"0"
selected=
"selected"
>0</option>
<option value=
"1"
>1</option>
<option value=
"3"
>3</option>
<option value=
"5"
>5</option>
<option value=
"7"
>7</option>
<option value=
"10"
>10</option>
</select>
</td>
<td width=
"42"
><input type=
"submit"
name=
"Submit"
value=
"提交"
/></td>
</tr>
</table>
</form>
</div>
<div>
<span>
<h3>打包权重信息:</h3>
</span>
<pre>
<?php
//$ret_str=system("sh /home/scripts/ms_change_pack.sh.onlyxiao check query ",$ret);
?>
</pre>
</div>
<div>
<pre>
<?php
if
(isset(
$_POST
[
'sel_ip'
]) && isset(
$_POST
[
'pack_right'
]) ){
if
(
$_POST
[
'sel_ip'
]==
""
||
$_POST
[
'pack_right'
]==
""
){
echo
"POST ERROR !"
;
return
;
}
$sel_ip
=
$_POST
[
'sel_ip'
];
$pack_right
=
$_POST
[
'pack_right'
];
echo
"$sel_ip $pack_right "
.
$_SERVER
[
'REMOTE_ADDR'
];
log_write_file(
$_COOKIE
[
'uname'
],
$_SERVER
[
'REMOTE_ADDR'
],
$sel_ip
,
$pack_right
);
$ret_str
=system(
"sh /home/scripts/ms_change_pack.sh.onlyxiao $sel_ip $pack_right "
,
$ret
);
}
?>
</pre>
</div>
<div>
<span>
<h3>包权重信息:</h3>
</span>
<pre>
<?php
$ret_str
=system(
"sh /home/scripts/ms_change_pack.sh.onlyxiao check query "
,
$ret
);
?>
</pre>
<h5>代码执行完成<h5/>
</div>
</body>
</html>
|
2. SHELL
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#!/bin/bash
USER_NO=$(
id
|
grep
-P
"richmail|root"
)
if
[[ -z $USER_NO ]] ;
then
echo
" run must in richmail user"
exit
1
fi
TIME=$(
date
"+%Y%m%d%H%M%S"
)
DATE=$(
date
"+%Y-%m-%d"
)
export
PATH=
/bin
:
/bin
:
/usr/kerberos/sbin
:
/usr/kerberos/bin
:
/usr/local/sbin
:
/usr/bin
:
/bin
:
/usr/sbin
:
/sbin
:
/root/bin
:
/usr/local/bin/
:$PATH
export
LD_LIBRARY_PATH=:
/home/richmail/oracle_client/lib
:
/home/richmail/lib
:
/home/richmail/oracle_client/lib
:
/home/richmail/lib
export
RICHMAIL_HOME=
/home/richmail
HOST_CONF=
/home/richmail/newconf/hosts
.conf
HOST_BAK_dir=
/home/scripts/hostconf_bak/
LOGFILE=${HOST_BAK_dir}
/logs/ms_change_packlog
.${DATE}
#HOST_CONF=/tmp/hosts.conf
#HOST_BAK_dir=/tmp/hostconf_bak/
#LOGFILE=${HOST_BAK_dir}/logs/change_packlog.${DATE}
if
[ $
# != 2 ];then
echo
"USAGE:$0 The two parameter"
echo
"USAGE:$0 incoming parameters digit 1 or 3 or 5 or 7:"
echo
"USAGE:$0 all_9qi|[192.168.220.1-38] 3"
exit
1;
fi
IP_MS=$1
PACK_R=$2
if
[[
"$IP_MS"
==
"check"
&&
"$PACK_R"
==
"query"
]];
then
sed
-rn
'/^ip=192.168.220.1/,/cloud-ms-38\/logreport/p'
$HOST_CONF|
awk
'{if($0~/^ip=192.168.220./){if(int(substr($0,16))<=38){printf "%s ",$0;flag=1}};if($1~/pack_thread_num/ && flag==1){printf "%d\n",$3}}'
echo
"end of query"
exit
0
fi
if
[[ ! -d ${HOST_BAK_dir} ]] ;
then
mkdir
-p ${HOST_BAK_dir}
chown
richmail.richmail ${HOST_BAK_dir}
fi
if
[[ ! -d ${HOST_BAK_dir}
/logs
]] ;
then
mkdir
-p ${HOST_BAK_dir}
/logs
chown
richmail.richmail ${HOST_BAK_dir}
/logs
fi
cp
-avpR $HOST_CONF ${HOST_BAK_dir}
/hosts
.conf.${TIME} >> $LOGFILE
chown
richmail.richmail $LOGFILE
if
[[ $? -
ne
0 ]] ;
then
echo
"$TIME cp error, script quit ! "
>> $LOGFILE
exit
1
fi
echo
"$TIME pack_thread change $IP_MS $PACK_R"
>> $LOGFILE
if
[[
"$IP_MS"
==
"all"
]] ;
then
# sed -ri '/^ip=192.168.220.1/,${/\bpack_thread_num\b/{s/ =.*/ = '"$PACK_R"'/g}}' $HOST_CONF
sed
-ri
'/^ip=192.168.220.1/,/cloud-ms-38\/logreport/{/\bpack_thread_num\b/{s/ =.*/ = '
"$PACK_R"
'/g}}'
$HOST_CONF
diff
$HOST_CONF ${HOST_BAK_dir}
/hosts
.conf.${TIME}
# sed -rn '/^ip=192.168.220.1/,${/\bpack_thread_num\b/{s/ =.*/ = '"$PACK_R"'/gp}}' $HOST_CONF >> $LOGFILE
echo
5 |
/home/richmail/bin/confutil
;
echo
0
for
((i=1;i<=38;i++));
do
echo
y |
/home/richmail/bin/richmail
--sys-restart 192.168.220.${i} mssvr >>
/home/scripts/logs/ms_change_pack
.log.${DATE} 2>&1
echo
y |
/home/richmail/bin/richmail
--sys-restart 192.168.220.${i} mssvr
echo
"all: 192.168.220.${i} restart"
done
diff
$HOST_CONF ${HOST_BAK_dir}
/hosts
.conf.${TIME} >> $LOGFILE
#sed -rn '/^ip=192.168.220.1/,${/\bpack_thread_num\b/{s/ =.*/ = '"$PACK_R"'/gp}}' $HOST_CONF >> $LOGFILE
exit
0
else
if
[[ -z $(
echo
$IP_MS|
grep
-P
"^192\.168\.220\.([1-9]|1[0-9]|2[0-9]|3[0-8])$"
) ]];
then
echo
"parameter not right all_9qi|[192.168.220.1-38]"
;
exit
1;
fi
#IP_MS_PLUS="192.168.220."$((${IP_MS##*.}+1))
IP_MS_PLUS=$((${IP_MS
##*.}+1))
echo
"${IP_MS}iiiiii${IP_MS_PLUS}"
sed
-ri
'/^ip=\b'
"${IP_MS}"
'\b$/,/^ip=192.168.220.\b'
${IP_MS_PLUS}
'\b$/{/\bpack_thread_num\b/{s/ =.*/ = '
"$PACK_R"
'/g}}'
$HOST_CONF
diff
$HOST_CONF ${HOST_BAK_dir}
/hosts
.conf.${TIME}
echo
5 |
/home/richmail/bin/confutil
;
echo
0
echo
y |
/home/richmail/bin/richmail
--sys-restart $IP_MS mssvr
echo
"restart ${IP_MS}"
diff
$HOST_CONF ${HOST_BAK_dir}
/hosts
.conf.${TIME} >> $LOGFILE
exit
0
|