-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetdata
executable file
·41 lines (34 loc) · 1.19 KB
/
getdata
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
#!/bin/bash
HADOOP_HOME='/home/excelle08/hadoop'
NAMENODE='tmp/namenode-metrics.out'
DATANODE='tmp/datanode-metrics.out'
task_name=$1
start_time=$2
end_time=$3
if [ -z "$1" -o -z "$2" -o -z "$3" ];then
echo "Usage: $0 <Task name> <Start time> <End time>";
exit 0;
fi
if ! [ -f "namenode" -a -f "datanode" ];then
echo "Namenode or datanode file does not exist.";
exit 1;
fi
if [ -d $task_name ];then
i=1
while [ -d "$task_name.$i" ];do
i=`expr $i + 1`;
done
task_name=$task_name.$i;
fi
mkdir -p $task_name;
echo "Get namenode:"
cat namenode | while read -r node;
do
ssh -n $node "cat $HADOOP_HOME/$NAMENODE | grep dfs.namenode | while read -r line;do time=\`echo \$line | cut -d ' ' -f 1\`;if [ \$time -ge $start_time -a \$time -le $end_time ];then echo \$line;fi done" > $task_name/$node.namenode.out;
printf "$node\r"
done
echo "Get datanode in parallel:"
cat datanode | while read -r node;
do
(ssh -n $node "cat $HADOOP_HOME/$DATANODE | grep dfs.datanode | while read -r line;do time=\`echo \$line | cut -d ' ' -f 1\`;if [ \$time -ge $start_time -a \$time -le $end_time ];then echo \$line;fi done" > $task_name/$node.datanode.out;printf "$node\r") &
done