-
Notifications
You must be signed in to change notification settings - Fork 8
/
remote_change_config
executable file
·54 lines (47 loc) · 1.07 KB
/
remote_change_config
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
#!/bin/bash
source_functions()
{
. conf/itennis.conf
. scripts/log_print
. scripts/exec_remote
}
show_help()
{
echo
echo "Usage: remote_change_config parameter1 parameter2 parameter3"
echo "以下变量说明:"
echo " parameter1:需要修改旧内容"
echo " parameter2:需要修改新内容"
echo " parameter3:需要修改的文件"
echo
return 0
}
main()
{
source_functions
if [ $# -lt 3 ]; then
show_help
return 1
fi
timeout=$REMOTE_TIMEOUT
port=$REMOTE_PORT
old_config=$1
new_config=$2
config_file=$3
cmd="sed -i 's/$old_config/$new_config/g' $config_file"
grep -v "^#" conf/hosts.list | while read line
do
host_ip=`echo $line | awk '{print $1}'`
username=`echo $line | awk '{print $3}'`
password=`echo $line | awk '{print $4}'`
exec_cmd_r $port $timeout $host_ip $username $password "if [[ \` grep -v '^#' $3 | grep -i '$2' | wc -l\` == 0 || '$2' == '' ]];then $cmd; fi"
if [ $? == 0 ];then
log INFO "$cmd execute in $host_ip success"
else
log ERROR "$cmd execute in $host_ip failed"
fi
done
}
umask 027
main "$@"
exit $?