-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathstart_quick_itennis.sh
executable file
·367 lines (355 loc) · 14.1 KB
/
start_quick_itennis.sh
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
#!/bin/bash
isContinue='y'
function isNext()
{
read -p 'Confirm whether to continue?[y/n]' isContinue
if [ "$isContinue" = "n" ];then
exit 1
elif [ "$isContinue" = "y" ];then
return 0
else
isNext
fi
}
source_functions()
{
. conf/itennis.conf
. scripts/log_print
. scripts/exec_remote
. scripts/packets_install
}
function ssh_to_otherswithonpwd()
{
hostfile=conf/hosts.list
read -p "please input host list file[$hostfile]: " INPUT
if [ x$INPUT != x ]; then
hostfile=$INPUT
fi
log INFO "ssh others with on password in $hostfile start"
sh scripts/sshx_to_others_with_nopwd $hostfile
log INFO "ssh others with on password in $hostfile end"
}
function remote_exe_changeconfig()
{
read -p "please input old value: "
oldv=$REPLY
read -p "please input new value: "
newv=$REPLY
read -p "please input modify file: "
vfile=$REPLY
cmd="sed -i 's/$oldv/$newv/g' $vfile"
CMDS_LIST=/tmp/cmds_list.$$
CONF_LIST=${HOSTS_CONF}
BG='y'
(
cat << EOF
if [[ \`grep -v '^#' $vfile | grep -i '$newv' | wc -l\` == 0 || '$newv' == '' ]];then $cmd; fi
EOF
) > ${CMDS_LIST}
sh exec_morelist.sh ${CONF_LIST} ${CMDS_LIST} $BG
rm /tmp/*.$$
}
function clear_mbr()
{
echo -e "\033[31m[NOTE] 清除MBR后,当前操作系统重启后将不能引导正常引导,主要解决重装操作系统不能正常引导问题!!!\033[0m"
isNext
CMDS_LIST=/tmp/cmds_list.$$
CONF_LIST=${HOSTS_CONF}
BG='y'
(
cat << EOF
dd if=/dev/zero of=/dev/sda bs=1k count=1 && echo 'Clear MBR OK' || echo 'Clear MBR failed'
EOF
) > ${CMDS_LIST}
sh exec_morelist.sh ${CONF_LIST} ${CMDS_LIST} $BG
rm /tmp/*.$$
}
function config_time_zero()
{
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime;hwclock &> /dev/null
read -p "please input current time[`date \"+%Y-%m-%d %H:%M:%S\"`]:"
if [ "`echo $REPLY`" != "" ];then
date -s "$REPLY" &> /dev/null
fi
CMDS_LIST=/tmp/cmds_list.$$
CONF_LIST=${HOSTS_CONF}
BG='y'
(
cat << EOF
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime;hwclock &> /dev/null;date -s \"`date '+%Y-%m-%d %H:%M:%S'`\" &> /dev/null
EOF
) > ${CMDS_LIST}
sh exec_morelist.sh ${CONF_LIST} ${CMDS_LIST} $BG
rm /tmp/*.$$
}
function batch_yum_completed()
{
serverip=$SERVER_IP
tmpdir=$TMPDIR
src="tools/yum_remote.sh"
CMDS_LIST=/tmp/cmds_list.$$
CMDS2_LIST=/tmp/cmds2_list.$$
CONF_LIST=${HOSTS_CONF}
BG='y'
(
cat << EOF
mkdir -p $tmpdir
EOF
) > ${CMDS_LIST}
sh exec_morelist.sh ${CONF_LIST} ${CMDS_LIST} $BG
sh exescp_list.sh $CONF_LIST $src $tmpdir
(
cat << EOF
sh $tmpdir/yum_remote.sh $serverip/os/$INSTALL_OS/$OS_VERSION
rm -rf $tmpdir
EOF
) > ${CMDS2_LIST}
sh exec_morelist.sh ${CONF_LIST} ${CMDS2_LIST} $BG
rm /tmp/*.$$
}
function batch_config_bmcinfo()
{
timeout=$REMOTE_TIMEOUT
port=$REMOTE_PORT
tmpdir=$TMPDIR
src="tools/ipmi_ip_config.sh"
grep -v "^#" conf/bmc_ip.conf | while read line
do
arr=(${line///\t/ })
length=${#arr[@]}
cmd=""
cmd="sh $TMPDIR/ipmi_ip_config.sh ${arr[3]} ${arr[4]} ${arr[5]};"
log DEBUG "exec_cmd_r $port $timeout ${arr[0]} ${arr[1]} ${arr[2]} \"$cmd\""
exec_cmd_r $port $timeout ${arr[0]} ${arr[1]} ${arr[2]} "mkdir -p $tmpdir"
cp_file_to_r $port $timeout ${arr[0]} ${arr[1]} ${arr[2]} "$src" "$tmpdir"
exec_cmd_r $port $timeout ${arr[0]} ${arr[1]} ${arr[2]} "$cmd"
exec_cmd_r $port $timeout ${arr[0]} ${arr[1]} ${arr[2]} "rm -rf $tmpdir"
done
}
function batch_bond()
{
timeout=$REMOTE_TIMEOUT
port=$REMOTE_PORT
tmpdir=$TMPDIR
src="tools/bonding.sh"
grep -v "^#" conf/bond_and_team.conf | while read line
do
arr=(${line///\t/ })
length=${#arr[@]}
tmpv=$(( ($length-3)%7 ))
if [ $tmpv != 0 ];then
log ERROR "Please check conf/bond_and_team.conf files failed"
exit
fi
tmpx=$(( ($length-3)/7 ))
cmd=""
for (( i=0;i<tmpx;i++ ))
do
cmd=$cmd"sh $TMPDIR/bonding.sh ${arr[i*7+3]} ${arr[i*7+4]} ${arr[i*7+5]} ${arr[i*7+6]} ${arr[i*7+7]} ${arr[i*7+8]} ${arr[i*7+9]};"
done
log DEBUG "exec_cmd_r $port $timeout ${arr[0]} ${arr[1]} ${arr[2]} \"$cmd\""
ping -c 3 -i 0.2 -W 3 ${arr[0]} &> /dev/null
if [ $? -eq 0 ];then
log INFO "ping ${arr[0]} success"
else
log ERROR "ping ${arr[0]} failed"
continue
fi
exec_cmd_r $port $timeout ${arr[0]} ${arr[1]} ${arr[2]} "mkdir -p $tmpdir"
cp_file_to_r $port $timeout ${arr[0]} ${arr[1]} ${arr[2]} "$src" "$tmpdir"
exec_cmd_r $port $timeout ${arr[0]} ${arr[1]} ${arr[2]} "$cmd"
exec_cmd_r $port $timeout ${arr[0]} ${arr[1]} ${arr[2]} "rm -rf $tmpdir"
#log WARN "Modification Configuration Completed,Network is restarting..."
#exec_cmd_r $port $timeout ${arr[0]} ${arr[1]} ${arr[2]} "service network restart" &> /dev/null
done
CMDS_LIST=/tmp/cmds_list.$$
CONF_LIST=/tmp/conf_list.$$
awk '{print $1"\t"$1"\t"$2"\t"$3}' conf/bond_and_team.conf > ${CONF_LIST}
BG='y'
(
cat << EOF
service NetworkManager stop &> /dev/null || echo "Graphical Network Manager service stop"
chkconfig NetworkManager off &> /dev/null || echo "Graphical Network Manager service off"
#service network restart &> /dev/null || echo "Network is restarting,could be timeout!"
echo "Network is restarting,could be timeout!" && service network restart &> /dev/null
EOF
) > ${CMDS_LIST}
sh exec_morelist.sh ${CONF_LIST} ${CMDS_LIST} $BG
rm /tmp/*.$$
}
function batch_team()
{
timeout=$REMOTE_TIMEOUT
port=$REMOTE_PORT
tmpdir=$TMPDIR
src="tools/teaming.sh"
grep -v "^#" conf/bond_and_team.conf | while read line
do
arr=(${line///\t/ })
length=${#arr[@]}
tmpv=$(( ($length-3)%7 ))
if [ $tmpv != 0 ];then
log ERROR "Please check conf/bond_and_team.conf files failed"
exit
fi
tmpx=$(( ($length-3)/7 ))
cmd=""
for (( i=0;i<tmpx;i++ ))
do
cmd=$cmd"sh $TMPDIR/teaming.sh ${arr[i*7+3]} ${arr[i*7+4]} ${arr[i*7+5]} ${arr[i*7+6]} ${arr[i*7+7]} ${arr[i*7+8]} ${arr[i*7+9]};"
done
log DEBUG "exec_cmd_r $port $timeout ${arr[0]} ${arr[1]} ${arr[2]} \"$cmd\""
ping -c 3 -i 0.2 -W 3 ${arr[0]} &> /dev/null
if [ $? -eq 0 ];then
log INFO "ping ${arr[0]} success"
else
log ERROR "ping ${arr[0]} failed"
continue
fi
exec_cmd_r $port $timeout ${arr[0]} ${arr[1]} ${arr[2]} "mkdir -p $tmpdir"
cp_file_to_r $port $timeout ${arr[0]} ${arr[1]} ${arr[2]} "$src" "$tmpdir"
exec_cmd_r $port $timeout ${arr[0]} ${arr[1]} ${arr[2]} "$cmd"
exec_cmd_r $port $timeout ${arr[0]} ${arr[1]} ${arr[2]} "rm -rf $tmpdir"
#log WARN "Modification Configuration Completed,Network is restarting..."
#exec_cmd_r $port $timeout ${arr[0]} ${arr[1]} ${arr[2]} "service network restart" &> /dev/null
done
CMDS_LIST=/tmp/cmds_list.$$
CONF_LIST=/tmp/conf_list.$$
awk '{print $1"\t"$1"\t"$2"\t"$3}' conf/bond_and_team.conf > ${CONF_LIST}
BG='y'
(
cat << EOF
service network restart &> /dev/null
EOF
) > ${CMDS_LIST}
sh exec_morelist.sh ${CONF_LIST} ${CMDS_LIST} $BG
rm /tmp/*.$$
}
function change_ip()
{
timeout=$REMOTE_TIMEOUT
port=$REMOTE_PORT
tmpdir=$TMPDIR
src="tools/change_ip_tmp.sh"
grep -v "^#" conf/change_ip.conf | while read line
do
arr=(${line///\t/ })
length=${#arr[@]}
tmpv=$(( ($length-2)%4 ))
if [ $tmpv != 0 ];then
log ERROR "Please check conf/change_ip.conf files failed"
exit
fi
tmpx=$(( ($length-2)/4 ))
cmd=""
for (( i=0;i<tmpx;i++ ))
do
cmd=$cmd"sh $TMPDIR/change_ip_tmp.sh ${arr[i*4+2]} ${arr[i*4+3]} ${arr[i*4+4]} ${arr[i*4+5]};"
done
log DEBUG "exec_cmd_r $port $timeout ${arr[2]} ${arr[0]} ${arr[1]} \"$cmd\""
exec_cmd_r $port $timeout ${arr[2]} ${arr[0]} ${arr[1]} "mkdir -p $tmpdir"
cp_file_to_r $port $timeout ${arr[2]} ${arr[0]} ${arr[1]} "$src" "$tmpdir"
exec_cmd_r $port $timeout ${arr[2]} ${arr[0]} ${arr[1]} "$cmd"
exec_cmd_r $port $timeout ${arr[2]} ${arr[0]} ${arr[1]} "rm -rf $tmpdir"
log WARN "Modification Configuration Completed,Network is restarting..."
exec_cmd_r $port $timeout ${arr[2]} ${arr[0]} ${arr[1]} "service network restart" &> /dev/null
done
CMDS_LIST=/tmp/cmds_list.$$
CONF_LIST=/tmp/conf_list.$$
awk '{print $3"\t"$3"\t"$1"\t"$2}' conf/change_ip.conf | grep -v "#" > ${CONF_LIST}
BG='y'
(
cat << EOF
service network restart &> /dev/null
EOF
) > ${CMDS_LIST}
sh exec_morelist.sh ${CONF_LIST} ${CMDS_LIST} $BG
rm /tmp/*.$$
}
function batch_change_rootpwd()
{
CMDS_LIST=/tmp/cmds_list.$$
CONF_LIST=${HOSTS_CONF}
BG='y'
read -p "please input root new password: "
newpwd=$REPLY
(
cat << EOF
echo $newpwd | passwd --stdin root
EOF
) > ${CMDS_LIST}
sh exec_morelist.sh ${CONF_LIST} ${CMDS_LIST} $BG
rm /tmp/*.$$
}
function more_functions()
{
echo "*************Please Input******************"
echo "** [1]:获到DHCP服务器分发的IP地址 **"
echo "** [q]:退出 **"
echo "****@iTennis By [email protected]****"
read -p "Please input [0-9,q]: " INPUT
case "$INPUT" in
[1] ) echo "获到DHCP服务器分发的IP地址" ;sh scripts_more/get_dhcp_ip.sh;;
[q] ) echo "退出" ;display;;
* ) echo "Input Error!" ;;
esac
echo -e "\n"
more_functions
}
function display()
{
echo "****************************************Please Input***********************************"
echo "** [1]:配置PXE环境 ** [a]:解决重装操作系统无法引导 **"
echo "** [2]:批量双网卡绑定Bond模式配置 ** [b]:批量双网卡绑定Team模式配置 **"
echo "** [3]:时区和时间配置 ** [c]:本机免密钥通信 **"
echo "** [4]:批量配置RAID ** [d]:批量更换IP地址 **"
echo "** [5]:收集硬件配置信息,检查网络连通性 ** [e]:批量配置BMC地址 **"
echo "** [6]:批量配置YUM源 ** [f]:本地Yum仓库源配置 **"
echo "** [7]:批量拷贝文件 ** [g]:批量修改文件内容 **"
echo "** [8]:批量执行命令 ** [h]:批量更换Root密码 **"
echo "** [9]:批量拷贝文件到本地 ** [i]:检查文件权限及属组 **"
echo "** [q]:退出 ** [m]:更多 **"
echo "***********************@iTennis By [email protected]*****************************"
read -p "Please input [0-9,a-j,q,r]: " INPUT
case "$INPUT" in
[1] ) echo "配置PXE环境" ;sh pxe_config.sh;;
[2] ) echo "批量双网卡绑定Bond模式配置" ;batch_bond;;
[3] ) echo "时区和时间配置" ;config_time_zero;;
[4] ) echo "批量配置RAID" ;sh locals/make_raid;;
[5] ) echo "收集硬件配置信息,检查网络连通性" ;sh check_lld;;
[6] ) echo "批量配置YUM源" ;batch_yum_completed;;
[7] ) echo "批量拷贝文件" ;sh generate_scps.sh;;
[8] ) echo "批量执行命令" ;sh generate_input_cmd.sh;;
[9] ) echo "批量拷贝文件到本地" ;sh generate_scp_tolocal.sh;;
[a] ) echo "解决重装操作系统无法引导" ;clear_mbr;;
[b] ) echo "批量双网卡绑定Team模式配置" ;batch_team;;
[c] ) echo "本机免密钥通信" ;ssh_to_otherswithonpwd;;
[d] ) echo "批量更换IP地址" ;change_ip;;
[e] ) echo "批量配置BMC地址" ;batch_config_bmcinfo;;
[f] ) echo "本地Yum仓库源配置" ;sh scripts/yum_config;;
[g] ) echo "批量修改文件内容" ;remote_exe_changeconfig;;
[h] ) echo "批量更换Root密码" ;batch_change_rootpwd;;
[i] ) echo "检查文件权限及属组" ;sh check_permission;;
[m] ) echo "更多" ;more_functions;;
[q] ) echo "退出" ;exit 0;;
* ) echo "Input Error!" ;;
esac
echo -e "\n"
display
}
help()
{
echo "This is a generic command line parser demo."
echo "USAGE EXAMPLE: ./cmdparser -l hello -f -- -somefile1 somefile2"
echo "HELP"
exit 0
}
source_functions
#PS4="#[Note]:"
#set -x
for file in `ls conf/* | grep -v "itennis.conf"`; do sed -i '/^\s*$/d' $file; done
if [ ! -n "$1" ];then
display
elif [[ "$1" = "-v" ]];then
echo "iTennis version:$VERSION"
fi