5bbc108cff91f9ead5249e6db6918eef876b10da
[myops.git] / web / collect / client / collect.sh
1 #!/bin/bash 
2
3 if [ -f /etc/planetlab/plc_config ]; then
4         source /etc/planetlab/plc_config
5 else
6         PLC_SLICE_PREFIX='pl'
7 fi
8 LOGFILE=/home/${PLC_SLICE_PREFIX}_myops/myops.log
9
10 cd /home/${PLC_SLICE_PREFIX}_myops
11
12 # TODO: add a timeout to eval, that kills children after X seconds
13 function write_key_command ()
14 {
15     key=$1
16     command=$2
17     value=`eval $command`
18     write_key_value "$key" "$value"
19 }
20 function write_key_value ()
21 {
22     key=$1
23     value=$2
24     (
25         flock -s 200
26         echo $key : $value >> $LOGFILE
27     ) 200>/var/lock/myops
28 }
29
30 rm -f $LOGFILE
31 count=0
32
33 while read key colon command ; do
34         if [[ $colon = ":" ]] ; then
35                 write_key_command "$key" "$command" &
36                 count=$(( $count + 1 ))
37         else
38                 if [[ $colon = ":=" ]] ; then
39                         eval $key=`eval $command`
40                 else if [[ $colon = "()" ]] ; then
41                         eval "function $key () $command"
42                      fi
43                 fi
44         fi
45 done < <( curl --silent http://IPADDR/PlanetLabConf/input.cfg )
46
47 write_key_value "count" "$count"
48
49