X-Git-Url: http://git.onelab.eu/?p=myops.git;a=blobdiff_plain;f=web%2Fcollect%2Fclient%2Fcollect.sh;fp=web%2Fcollect%2Fclient%2Fcollect.sh;h=5bbc108cff91f9ead5249e6db6918eef876b10da;hp=0000000000000000000000000000000000000000;hb=85070b3d456667f238051af1a2f1f2a0c12300ab;hpb=607f0e13927eb18075c375fa9ba5527da4fcbb44 diff --git a/web/collect/client/collect.sh b/web/collect/client/collect.sh new file mode 100644 index 0000000..5bbc108 --- /dev/null +++ b/web/collect/client/collect.sh @@ -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" + +