How can i get only IP and which interface IP it is? So that i can keep a record file such as realtime.ini
1 - test.sh
#!/bin/bash
ipstring ='inet (.*)'
for i in $(ip addr);
do
echo $i #on found it write down to my realtime.ini as a list for future query
done
2 - realtime.ini
em1,192.168.1.2
lo,127.0.0.1
wlan0,<not found>
Follow up: Just for single ip: $ ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}' 192.168.1.2
if you install
moreutils
package, you can use handyifdata
command:example output for 5 interfaces, while only
eth0
andlo
are up:This is not terribly elegant, nor is bash, but you can do the following if you have both awk and sed:
I wouldn't bet on this being hugely portable either, so maybe someone has a better answer.