Results 1 to 7 of 7
Hi!
I'm trying to order my outpu as I like but I have problems.
I have this:
Code:
/sbin/ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 ...
- 01-12-2010 #1Just Joined!
- Join Date
- Oct 2008
- Posts
- 48
Script to show IP's
Hi!
I'm trying to order my outpu as I like but I have problems.
I have this:
the result is:Code:/sbin/ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}' > $LOG_TMP for i in $LOG_TMP; do IPS=`echo $i` done
[5.5.5.9]
[5.5.5.10]
but I would like to see as:
[5.5.5.9] [5.5.5.10]
How can do this???
- 01-12-2010 #2
How about:
Code:/sbin/ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}' > $LOG_TMP ips="" for i in $LOG_TMP; do ips="${ips} ${i}" done echo $ipsLinux User #453176
- 01-12-2010 #3Just Joined!
- Join Date
- Oct 2008
- Posts
- 48
the output is the same as my script. I only change the last echo for a more
- 01-12-2010 #4Linux User
- Join Date
- Nov 2009
- Location
- France
- Posts
- 292
Can't understand howCode:/sbin/ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}' > $LOG_TMP ips="" while read i; do ips="${ips} ${i}" done < $LOG_TMP echo $ips
can producefor i in $LOG_TMP
LOG_TMP is not a list of values.[5.5.5.9]
[5.5.5.10]
or
[5.5.5.9] [5.5.5.10]
- 01-12-2010 #5
It doesn't. That line just loops through each value in the list. The line:
Creates a variable containing all of the values in the list. So after the loop has complete the state of the application should be that:Code:ips="${ips} ${i}"
Then the echo will print this to stdoutCode:ips=" [5.5.5.9] [5.5.5.10]"
Linux User #453176
- 01-12-2010 #6
Okay, this works for me:
Output:Code:LOG_TMP=/tmp/test /sbin/ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}' > $LOG_TMP ips="" for i in `cat ${LOG_TMP}`; do ips="${ips} ${i}" done echo $ips
Code:kieren@George-Michael:~$ ifconfig eth0 Link encap:Ethernet HWaddr 00:18:f3:0c:21:e1 inet addr:192.168.1.9 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::218:f3ff:fe0c:21e1/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:196282 errors:0 dropped:0 overruns:0 frame:0 TX packets:246967 errors:0 dropped:0 overruns:0 carrier:0 collisions:3246 txqueuelen:1000 RX bytes:95351045 (95.3 MB) TX bytes:122916280 (122.9 MB) Interrupt:23 Base address:0xc800 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:24 errors:0 dropped:0 overruns:0 frame:0 TX packets:24 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1240 (1.2 KB) TX bytes:1240 (1.2 KB) wlan0 Link encap:Ethernet HWaddr 00:1f:1f:01:93:38 inet addr:192.168.1.11 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::21f:1fff:fe01:9338/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1571 errors:0 dropped:0 overruns:0 frame:0 TX packets:24 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:347596 (347.5 KB) TX bytes:5008 (5.0 KB) wmaster0 Link encap:UNSPEC HWaddr 00-1F-1F-01-93-38-30-31-00-00-00-00-00-00-00-00 UP RUNNING MTU:0 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) kieren@George-Michael:~$ ./test 192.168.1.9 192.168.1.11Linux User #453176
- 01-13-2010 #7Just Joined!
- Join Date
- Oct 2008
- Posts
- 48
now it's work!
very thanks


Reply With Quote
