Add scripts to create myops-getqueryview:
[myops.git] / web / collect / client / collect.sh
diff --git a/web/collect/client/collect.sh b/web/collect/client/collect.sh
new file mode 100644 (file)
index 0000000..5bbc108
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/bash 
+
+if [ -f /etc/planetlab/plc_config ]; then
+       source /etc/planetlab/plc_config
+else
+       PLC_SLICE_PREFIX='pl'
+fi
+LOGFILE=/home/${PLC_SLICE_PREFIX}_myops/myops.log
+
+cd /home/${PLC_SLICE_PREFIX}_myops
+
+# TODO: add a timeout to eval, that kills children after X seconds
+function write_key_command ()
+{
+    key=$1
+    command=$2
+    value=`eval $command`
+    write_key_value "$key" "$value"
+}
+function write_key_value ()
+{
+    key=$1
+    value=$2
+    (
+        flock -s 200
+        echo $key : $value >> $LOGFILE
+    ) 200>/var/lock/myops
+}
+
+rm -f $LOGFILE
+count=0
+
+while read key colon command ; do
+        if [[ $colon = ":" ]] ; then
+                write_key_command "$key" "$command" &
+                count=$(( $count + 1 ))
+        else
+                if [[ $colon = ":=" ]] ; then
+                        eval $key=`eval $command`
+                else if [[ $colon = "()" ]] ; then
+                        eval "function $key () $command"
+                     fi
+                fi
+        fi
+done < <( curl --silent http://IPADDR/PlanetLabConf/input.cfg )
+
+write_key_value "count" "$count"
+
+