Quote |
IPADDR= IPADDR=`ifconfig eth0 | grep "inet addr"|cut -d':' -f2|cut -d' ' -f1` if [ ${IPADDR} = "00.00.00.00" ]; then assign your ip else do something else fi |
Quote (dtf @ Sep. 25 2006,08:30) | ||
One way might be to allow for dchp (the default boot option) and then use ifconfig to determine if an ip address has been assigned and base your actions on the results. An example
I am not sure what you get when there is no IP address assigned so you should double check. Another way you can check is to check for received packets. There might be better ways to accomplish this task but this is one idea. |
Code Sample |
IPADDR=`ifconfig eth0 | grep "inet addr"|cut -d':' -f2|cut -d' ' -f1` |
Quote |
Well, if there's no dhcp assigned address at boot, I think eth0 doesn't get added to ifconfig. It would only show lo (loobback 127.0.0.1). Looking up a nonexistent device in ifconfig results in: |
Quote |
if [ -z $IPADDR -o $IPADDR = "00.00.00.00" ]; then |
Quote |
Sidenote, is the subnetmask not needed? It's the plain /24 255.255.255.0 |