[olug] Unix Tip: GET YOUR IP-ADDRESS (long explanation)

Vincent vincentr at cox.net
Thu Mar 20 22:20:31 UTC 2003


Would you provide a long explanation for this one-line script ?  :)

[ $# -gt 0 ] && ( while [ "$1" ]; do ( [ -f $1 ] && [ "$( file $1 | grep text)" ] ) && ( echo -e "$( grep -vE
'^[[:space:]]*#|^[[:space:]]*$' $1 | wc -l | tr -d '[[:space:]]' )\t$1" ); shift; done ) || echo "Usage: $0 <file> [file file file
...]"



----- Original Message -----
From: "Eric Penne" <epenne at olug.org>
To: <olug at olug.org>
Sent: Thursday, March 20, 2003 2:11 PM
Subject: Re: [olug] Unix Tip: GET YOUR IP-ADDRESS (long explanation)


> ifconfig | grep "inet addr" |  grep -v "127.0.0.1" | awk '{print $2;}' |
> awk -F':' '{print $2;}'
>
>
> Here is a rundown on this command for the newbies.
>
> 1) ifconfig is usually located in /sbin/ifconfig shows the network
> interfaces that are up and how they are configured.
>
> 2) grep pulls lines out of the ifconfig info that contain inet addr
>
> 3) grep -v inverts.  It prints all the lines that don't have 127.0.0.1
> in them.
>
> 4) awk looks at the info and pulls the second field out, where the
> fields are separated by whitespace by default.
>
> 5) Then awk -F':' is used again to pull the second field out, where the
> fields are separated by a colon.
>
> The individual outputs follow:
>
> 1)
>
> eth0      Link encap:Ethernet  HWaddr 00:80:AD:0C:BA:43
>           inet addr:192.168.1.42  Bcast:192.168.255.255
> Mask:255.255.0.0 UP BROADCAST RUNNING MULTICAST  MTU:1500
> Metric:1
>           RX packets:34866 errors:0 dropped:0 overruns:0 frame:0
>           TX packets:5882 errors:0 dropped:0 overruns:0 carrier:0
>           collisions:0 txqueuelen:100
>           RX bytes:7133322 (6.8 MiB)  TX bytes:850473 (830.5 KiB)
>           Interrupt:3 Base address:0xd800
>
> lo        Link encap:Local Loopback
>           inet addr:127.0.0.1  Mask:255.0.0.0
>           UP LOOPBACK RUNNING  MTU:16436  Metric:1
>           RX packets:8 errors:0 dropped:0 overruns:0 frame:0
>           TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
>           collisions:0 txqueuelen:0
>           RX bytes:400 (400.0 b)  TX bytes:400 (400.0 b)
>
> 2)
>           inet addr:192.168.1.42  Bcast:192.168.255.255
> Mask:255.255.0.0 inet addr:127.0.0.1  Mask:255.0.0.0
>
> 3)
>           inet addr:192.168.1.42  Bcast:192.168.255.255
> Mask:255.255.0.0
>
> 4)
> addr:192.168.1.42
>
> 5)
> 192.168.1.42
>
>
> Now don't we all love the pipe command.  Hopefully if you are having
> trouble with the above command this explanation can step you through the
> issues.
>
> Eric
>
>
>
> _______________________________________________
> OLUG mailing list
> OLUG at olug.org
> http://lists.olug.org/mailman/listinfo/olug
>



More information about the OLUG mailing list