4e75182cd388cfaa1c467dc36b920545fae1f35f
[ltt-control.git] / tags / ltt-control-0.51-12082008 / lttctl / lttctl_distributed.sh
1 #!/bin/bash
2 # Copyright (C) 2006 Eric Clément
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # purpose : automatic generation of traces with LTT in a network.
14 # usage :
15 #
16 # you need SSH connection without password for all computers that you want
17 # trace. You might put le name of those computers (uname -n) in a file
18 # (liste.txt by default). LTT might be installed in the same way for those
19 # computer.
20 # You can customize your path. This script can also generate traffic TCP and
21 # UDP. A UDP monitor is use to validate the result (this is the first computer
22 # in the file (liste.txt)).
23 #
24 # usage: ./lttclt_distributed.sh time freq mode_generator {options}
25 #
26 # time (seconds) : duration a the tracing
27 # freq (nb packet/second or nb packet/ms) : communication frequency when TCP
28 # generator is used, 0 otherwise
29 # mode_generator : 1 : traffic generator off
30 # 2 : traffic generator TCP on (nb packet/second)
31 # 3 : traffic generator TCP on (nb packet/ms)
32 #
33 # options (optional): 1 : enable the UDP monitor (1packet/second is generated
34 # by all UDP client)
35 #
36 # you need : ssh, scp and zip
37
38 TCP_SERVER=tcpserver
39 TCP_CLIENT=tcpclient
40
41 UDP_SERVER=udpserver
42 UDP_CLIENT=udpclient
43
44 PATH_TRACE=/root/trace-ltt/
45 PATH_DEBUGFS=/debugfs/ltt/
46 SET_LTT_FACILITIES="export LTT_FACILITIES=/home/ercle/NEW_GENERATION_LTTV/share/LinuxTraceToolkitViewer/facilities/"
47 SET_LTT_DAEMON="export LTT_DAEMON=/home/ercle/NEW_GENERATION_LTTV/bin/lttd"
48
49 START_DAEMON="/home/ercle/NEW_GENERATION_LTTV/bin/lttctl -d -n \
50 trace1 -t $PATH_TRACE -l $PATH_DEBUGFS >/dev/null"
51
52 STOP_DAEMON="/home/ercle/NEW_GENERATION_LTTV/bin/lttctl -n trace1 -q >/dev/null"
53 REMOVE_DAEMON="/home/ercle/NEW_GENERATION_LTTV/bin/lttctl -n trace1 -r >/dev/null"
54 REMOVE_TRACE="rm -rf $PATH_TRACE"
55
56 E_FNEXIST=100
57
58 FILE_LISTE=liste.txt
59 TRACE_DAEMON=/tmp/daemon-
60
61 if [ $# -lt 3 ]
62 then
63 echo "usage: $0 time freq mode_generator {options}"
64 exit 1
65 elif [ $# -gt 4 ]
66 then
67 echo "usage: $0 time freq mode_generator {options}"
68 exit 1
69 fi
70
71 if [ -e $FILE_LISTE ]
72 then
73
74 time=$1
75 freq=$2
76 mode_generator=$3
77 if [ $# -eq 4 ]
78 then
79 mode_monitor=$4
80 else
81 mode_monitor=0
82 fi
83
84 #create script generator
85 FILE_OUT=daemon-
86
87 if [ $mode_generator -eq 3 ]
88 then
89 TCP_CLIENT=tcpclient_ms
90 fi
91
92 nb_node=0
93 for line in $( cat $FILE_LISTE );
94 do
95 let nb_node+=1
96
97 echo $REMOVE_TRACE > "$FILE_OUT$line.sh"
98 echo mkdir $PATH_TRACE >> "$FILE_OUT$line.sh"
99 echo $SET_LTT_FACILITIES >> "$FILE_OUT$line.sh"
100 echo $SET_LTT_DAEMON >> "$FILE_OUT$line.sh"
101 echo $START_DAEMON >> "$FILE_OUT$line.sh"
102
103 chmod +x "$FILE_OUT$line.sh"
104
105 if [ $mode_generator -ge 2 ] #if generator de trafic enable (2 or 3)
106 then
107 if [ $nb_node -eq 1 -a $mode_monitor -eq 1 ]
108 then
109 monitor=$line
110 echo "/tmp/$UDP_SERVER >/dev/null &" >> "$FILE_OUT$line.sh"
111 scp "$UDP_SERVER" $line:/tmp/
112
113 echo "sleep $time" >> "$FILE_OUT$line.sh"
114 echo "kill \`ps -A |grep $UDP_SERVER | awk '{ print \$1 }'\`" >> "$FILE_OUT$line.sh"
115 else
116 if [ $mode_monitor -eq 1 ]
117 then
118 echo "/tmp/$UDP_CLIENT $monitor $time 1 >/dev/null & " >> "$FILE_OUT$line.sh"
119 scp "$UDP_CLIENT" $line:/tmp/
120 fi
121
122 echo "/tmp/$TCP_SERVER >/dev/null &" >> "$FILE_OUT$line.sh"
123 scp "$TCP_SERVER" $line:/tmp/
124 compteur=0
125 for line2 in $( cat $FILE_LISTE );
126 do
127 let compteur+=1
128 if [ $compteur -gt $nb_node ]
129 then
130 echo "/tmp/$TCP_CLIENT $line2 $time $freq >/dev/null &" >> "$FILE_OUT$line.sh"
131 scp "$TCP_CLIENT" $line:/tmp/
132 fi
133 done
134
135 echo "sleep $time" >> "$FILE_OUT$line.sh"
136 echo "kill \`ps -A |grep $TCP_SERVER | awk '{ print \$1 }'\`" >> "$FILE_OUT$line.sh"
137 fi
138 fi
139
140 echo $STOP_DAEMON >> "$FILE_OUT$line.sh"
141 echo $REMOVE_DAEMON >> "$FILE_OUT$line.sh"
142
143 #script for get node information
144 ENDIAN=endian
145 echo 'FILE_OUT=`uname -n`.info' >> "$FILE_OUT$line.sh"
146 echo 'ENDIAN=endian' >> "$FILE_OUT$line.sh"
147 echo ' exec 6>&1' >> "$FILE_OUT$line.sh"
148 echo ' exec > /tmp/$FILE_OUT' >> "$FILE_OUT$line.sh"
149 echo ' echo `uname -n`' >> "$FILE_OUT$line.sh"
150 echo '' >> "$FILE_OUT$line.sh"
151 echo ' /tmp/$ENDIAN || ( echo >&6 && echo "** ERROR **: problem occur with /tmp/$ENDIAN" >&6 && echo >&6)' >> "$FILE_OUT$line.sh"
152 echo '' >> "$FILE_OUT$line.sh"
153 echo -e ' /sbin/ifconfig | grep addr: | awk \047{print $2}\047 | sed /127.0.0.1/d | sed s/addr:// | sed /^$/d #english' >> "$FILE_OUT$line.sh"
154 echo -e ' /sbin/ifconfig | grep adr: | awk \047{print $2}\047 | sed /127.0.0.1/d | sed s/adr:// | sed /^$/d #french' >> "$FILE_OUT$line.sh"
155 echo ' echo END' >> "$FILE_OUT$line.sh"
156 echo '' >> "$FILE_OUT$line.sh"
157 echo ' exec 1>&6 6>&-' >> "$FILE_OUT$line.sh"
158 echo '' >> "$FILE_OUT$line.sh"
159 echo ' echo "$FILE_OUT done"' >> "$FILE_OUT$line.sh"
160 echo '' >> "$FILE_OUT$line.sh"
161
162 #send files
163 if [ $mode_generator -ge 2 -a $nb_node -eq 1 -a $mode_monitor -eq 1 ]
164 then
165 echo mv /tmp/'`uname -n`'.info /tmp/'`uname -n`'.monitor >> "$FILE_OUT$line.sh"
166 echo scp /tmp/'`uname -n`'.monitor `uname -n`:`pwd`/ >> "$FILE_OUT$line.sh"
167 else
168 echo scp /tmp/'`uname -n`'.info `uname -n`:`pwd`/ >> "$FILE_OUT$line.sh"
169 fi
170
171 echo ' exit 0' >> "$FILE_OUT$line.sh"
172
173 scp "$FILE_OUT$line.sh" $line:/tmp/
174 scp "$ENDIAN" $line:/tmp/
175 rm "$FILE_OUT$line.sh"
176 done
177 #end script generator
178
179 #start traces !!
180 sleep 1
181
182 for line in $( cat $FILE_LISTE );
183 do
184 echo ssh -f "$line $TRACE_DAEMON$line.sh "
185 ssh -f $line "$TRACE_DAEMON$line.sh"
186 done
187
188 else
189 echo "error: file $FILE_LISTE doesn't exist"
190 exit E_FNEXIST
191 fi
192
193 date
194
195 sleep $time
196
197 # is all daemon stop ?
198 for line in $( cat $FILE_LISTE );
199 do
200
201 daemon_present="true"
202 wait_time=1
203 while [ $daemon_present == "true" ]
204 do
205 daemon_present="false"
206 (ssh $line ps -A |grep lttd) && daemon_present="true"
207 sleep $wait_time
208 let wait_time+=1
209 done
210 done
211
212 #get all traces
213 nb_computer=0
214 zip_path=""
215 for line in $( cat $FILE_LISTE );
216 do
217 mkdir `pwd`/$line 2>/dev/null
218 scp -q -r $line:$PATH_TRACE/ `pwd`/$line
219 zip_path="$zip_path $line"
220 let nb_computer+=1
221 done
222
223 #get network informatioin
224 FILE_TMP=ls.tmp
225 FILE_OUT=network.trace
226
227 exec 3> $FILE_TMP #open FILE_TMP (Write)
228
229 ls *.monitor >&3 2>/dev/null
230
231 #get the list of .info file to parse
232 ls *.info >&3 || (echo EMPTY >&3)
233 echo END >&3
234
235 exec 3>&- #close FILE_TMP
236
237 exec 3< $FILE_TMP #open FILE_TMP (Read)
238 read line <&3
239 if [ "$line" = "EMPTY" ]
240 then
241 echo "NO .info file"
242 exec 3>&- #close FILE_TMP
243 rm -rf $FILE_TMP
244 exit 1
245 fi
246
247 exec 5> $FILE_OUT #open FILE_OUT (Write)
248
249 echo -e "Nb IP\tName\t\endianness\tIP ..."
250 echo -e "Nb IP\tName\tendianness\tIP ..." >&5
251
252 while [ "$line" != "END" ]
253 do
254 echo "++++++++++++++++++++"
255 echo "in file $line"
256
257 output=""
258 nb_ip=-2 #1st line => name, 2 line => endianness
259 exec 4< $line
260 read answer <&4
261
262 while [ "$answer" != "END" ]
263 do
264 nb_ip=`expr $nb_ip + 1`
265 output="$output\n$answer"
266 read answer <&4
267 done
268
269 echo -e "$nb_ip$output"
270 echo -e "$nb_ip$output" >&5
271 exec 4<&-
272 mv $line "$line.read"
273 read line <&3
274 echo "---------------------"
275 done
276
277 exec 3>&- #close FILE_TMP
278 rm -rf $FILE_TMP
279 echo END >&5
280 exec 5<&- #close FILE_OUT
281
282 #zip files
283 root=`pwd`
284 cd $root && echo $root
285 nomfic="trace__nb_computer"$nb_computer"__time"$time"__freq"$freq"__"`uname -n``date '+__%d%b__%H-%M-%S'`$options".zip"
286
287 zip -r $nomfic $zip_path *.info.read *.monitor.read *.trace>/dev/null
288 echo -e "zip done $zip_path\n$root/$nomfic"
289
290 exec 3<&-
291
292 echo -e "\a$0 done!"
293 exit 0
This page took 0.035163 seconds and 3 git commands to generate.