linux - Is this an effective way to wait 10 seconds for an IP address? -
i have shell script creates vm use processing on. vm given random ip address obtain using vmwares vmrun
utility. machine can take anywhere 10 - 20 seconds before gets assigned ip address not default windows apipa
address.
sometimes arithmetic error, , other times don't... whats wrong code? why intermittently work?
ip=`vmrun -t ws readvariable my_vm guestvar ip` if [ ! -z `echo $ip | grep "169.254"` ] i=0 while [ ! -z `echo $ip | grep "169.254"` ] if [ $i -eq 10 ] echo "$ip has been unresponsive 10 seconds. quitting." exit 1 else sleep 1 i=$((i++)) # error occurs ip=`vmrun -t ws readvariable my_vm guestvar ip` fi done fi
is there better way this?
error message:
arithmetic expression: expecting primary: "i++"
the $
looks it's superfluous, can use ((i++))
without assignment increment variable.
Comments
Post a Comment