用shell脚本实现输出网络接口和IP地址,输出形式为:eth0 192.168.0.106
lo 127.0.0.1
lo 127.0.0.1
- #! /bin/bash
- # The prupose of the shell script is to obtian the ibterface IP address
- ifconfig |egrep 'eth0|lo|inet addr' |awk -F ' ' '{print $1,$2}' |grep -n '.*' |grep -i 'inet' |cut -d':' -f1,3 >2.txt
- ifconfig |egrep 'eth0|lo|inet addr' |awk -F ' ' '{print $1,$2}'|grep -n '.*'|grep -i 'link' |cut -d' ' -f1 >1.txt
- cat 1.txt 2.txt |sort|cut -d: -f2 |grep -A1 'eth0' >11.txt
- cat 1.txt 2.txt |sort|cut -d: -f2 |grep -A1 'lo' >22.txt
- cat 11.txt |xargs;cat 22.txt |xargs
编辑回复