Assigning DHCP IP Address to a variable

Assigning DHCP IP Address to a variable

Post by Hermini » Thu, 03 Jan 2002 11:27:14



Could someone tell me how to assign a DHCP IP address to a variable?  I
have a command that extracts the DHCP IP address but I can't assign the
results to a variable.  Here is the command:

        ifconfig eth0 | grep " addr:" | cut -d ":" -f2 | cut -f1 -d " "

I need to assign the results of the command above to a variable.
Preferrably DHCP_IP.

        I've tried DHCP_IP=<command> but that doesn't work.

Any help will be greatly appreciated.

 
 
 

Assigning DHCP IP Address to a variable

Post by Russe » Thu, 03 Jan 2002 12:56:50


+ Could someone tell me how to assign a DHCP IP address to a variable?  I
+ have a command that extracts the DHCP IP address but I can't assign the
+ results to a variable.  Here is the command:
+
+       ifconfig eth0 | grep " addr:" | cut -d ":" -f2 | cut -f1 -d " "
+

that's horrible. don't use cut, there's rarley a need for it. you're
forking two unnecessary processes.

you want something like;

var=`ifconfig eth0 | sed '/.*addr:/!d;s///;s/ .*//'`

r.

 
 
 

Assigning DHCP IP Address to a variable

Post by Hermini » Thu, 03 Jan 2002 14:50:31



> On Wed, 02 Jan 2002 02:27:14 GMT, Herminio

> assign a DHCP IP address to a variable?  I + have a command that
> extracts the DHCP IP address but I can't assign the + results to a
> variable.  Here is the command: +
> +  ifconfig eth0 | grep " addr:" | cut -d ":" -f2 | cut -f1 -d " " +

> that's horrible. don't use cut, there's rarley a need for it. you're
> forking two unnecessary processes.

> you want something like;

> var=`ifconfig eth0 | sed '/.*addr:/!d;s///;s/ .*//'`

> r.

Thank you very much. Your suggestion works. I'll try to keep my process
forking to a minimum. :)
 
 
 

1. DHCP Server doesn't assign IP address

I am recently installed the latest Mandrake Linux.  I am having no
luck getting DHCP to assign an ip address from my ISP.  I am using a
3com 3c59x card that appears to be functioning correctly.  I
usDHCP-client -3.0-2pl2.3mdk.  Using DrakeConfig everything seems to
go smoothly except I still don't have an IP address.  Is there a
command simular to windows IPCONFIG /RELEASE?  I've tried everything
and been through all the HOW TO's with no luck.

Bob

2. sparc misc binaries

3. howto: Setting /etc/hosts with DHCP assigned IP address -- a solution

4. freebsd driver for wavelan?

5. How to assign a permanent IP address using DHCP

6. Where is AS?

7. Let dhcp assign IP address for dial-in users?

8. Problems with dependencies for gimp-print

9. Getting a DHCP assigned IP Address at startup.

10. dhcp-server: assign fixed address to clients within MAC address range

11. Setting up DMZ, IP routing and assigning IP addresses

12. Correct IP configuration for machine with dynamically-assigned IP address?

13. 3com 905b gets Ip address by using DHCP from NT DHCP server