-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinclude.lib
More file actions
124 lines (111 loc) · 2.87 KB
/
Copy pathinclude.lib
File metadata and controls
124 lines (111 loc) · 2.87 KB
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
usage() {
format_usage="Usage:
\t\t command mode example:./mafia.sh -h \"10.0.7.1 10.0.7.2\" -f /tmp/da/passwd -c \"sort\" \n \
\t\t script mode example:./mafia.sh -h \"10.0.7.1 10.0.7.2\" -f /tmp/da/passwd -c script -s /tmp/s.py \n \
\n
\t\t [-h host]\t remote nodes ip address or hostname \n \
\t\t [-f filename]\t specifed data file,the data will be split and send to nodes \n \
\t\t [-c command]\t specifed command will be send to nodes. \n \
\t\t [-s script filename] specifed script handle you data. will be send to nodes."
echo -e $format_usage
}
local_check() {
if [ -z "$command" -o ! -f "$raw_data_file" ]
then
echo "data file not found or command no specifed"
exit
else
:
fi
}
node_is_live() {
idx=0
declare -a nodes=($1)
for nd in ${nodes[@]}
do
((idx++))
if ping -c 1 -W 1 $nd 1>/dev/null 2>&1
then
echo
else
echo "node: $nd conection fail,will be ignored"
unset node_list[idx-1]
fi
done
}
check_environ_requirement() {
#remote file exist
client_idx=0
for client in ${node_list[@]}
do
((client_idx++))
file_exist_and_executable=$(ssh $username@$client "[ -x "$node_hander_file" ]&&echo ok||echo fail")
client_port_available=$(ssh $username@$client "if /bin/netstat -nalt|grep 1080[3-4] 1>/dev/null 2>&1;then echo unavailabe;else echo availabe;fi" )
if [ "$file_exist_and_executable" == "ok" -a "$client_port_available" == "availabe" ]
then
:
else
# echo "$node_hander_file can't be executed or not found on node $client ,will be ignored"
echo "$node_hander_file can't be executed or not found on node $client, or client port unavailabe."
unset node_list[client_idx-1]
fi
done
}
split_raw_file() {
cd $data_store_dir
line=$(wc -l $1)
pices=${#node_list[@]}
echo $pices
if [ $pices -eq 1 ]
then
mv "$1" $1"00"
else
avg=$((${line%%/*}/$pices))
if [ $(expr ${line%%/*} % $avg) -gt 0 ]
then
avg=$(($avg+1))
else
:
fi
split -d -l $avg $1 ${1%.*}
fi
}
start_nodes() {
if [ ${#node_list[@]} -eq 0 ];
then
echo "no available nodes."
exit
else
for node_idx in `seq 0 $((${#node_list[@]}-1))`
do
ssh $username@${node_list[node_idx]} "sh /tmp/node.sh >/dev/null 2>&1 &"
done
fi
#wait nodes startup
sleep 2s
}
send_data_to_nodes() {
#send data to node
i=0
for file in $data_store_dir/*0*
do
cat $file |$NC ${node_list[i++]} $data_recv_port
echo "cat $file |$NC ${node_list[i++]} $data_recv_port"
done
}
send_commnad_to_nodes() {
#send command to data node
for node in ${node_list[@]}
do
echo "$command"|$NC $node $command_recv_port
echo "awk -F":" \'\$1 ~/root/{print \$0}\'|$NC $node $command_recv_port"
done
}
send_script_to_nodes() {
script_abs_filename=$1
local_filename=$2
for i in ${node_list[@]}
do
ssh $username@$i "cat - >$script_abs_filename" <$local_filename
done
}