function run_with_command () {
CMD=$1
TIMEOUT=$2
COUNTER=0
${CMD} &
CMD_PID=$!
while ps $CMD_PID > /dev/null && [ $COUNTER -lt $TIMEOUT ]; do
sleep 1
COUNTER=$((COUNTER+1))
done
if [ $COUNTER -eq $TIMEOUT ]
then
kill $CMD_PID 2>/dev/null
fi
wait $CMD_PID 2>/dev/null
}
No comments:
Post a Comment