#!/bin/bash function runcmd { local __resultvar=$1 sfile="/home/sportrum/webapp/sportrum/WEB-INF/storage/status.storeall.$pid" rm -f ${sfile} printf "storeall $pid" > /home/sportrum/webapp/sportrum/WEB-INF/storage/commands.txt || exit 1 sfile="/home/sportrum/webapp/sportrum/WEB-INF/storage/status.storeall.$pid" while [ ! -f $sfile ] do sleep 1 done while true do status=$(cut -d " " -f 1 $sfile) if [ "x$(echo $status | cut -d ':' -f 1)" == "xcompleted" ] then local funresult="$(echo $status | cut -d ':' -f 2)" eval $__resultvar="'$funresult'" break; else echo "$(cat $sfile)" sleep 1 fi done }