简体   繁体   English

一个shell脚本如何显示所有接口的IP地址?

[英]How to display IP address of all interface for a shell script?

I want to display all.network interface for a script, including vip.我想显示一个脚本的all.network界面,包括vip。

 ~]$ /sbin/ifconfig 
eth0      Link encap:Ethernet  HWaddr 00:50:56:90:88:37  
          inet addr:192.168.1.15  Bcast:192.168.1.31  Mask:255.255.255.224
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:9786341 errors:0 dropped:152 overruns:0 frame:0
          TX packets:10162602 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:6846599961 (6529.4 Mb)  TX bytes:2951709145 (2814.9 Mb)

eth1      Link encap:Ethernet  HWaddr 00:50:56:90:E1:2E  
          inet addr:25.10.100.15  Bcast:25.10.100.31  Mask:255.255.255.224
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:42436 errors:0 dropped:150 overruns:0 frame:0
          TX packets:35 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:5484037 (5.2 Mb)  TX bytes:2446 (2.3 Kb)

Like this像这样

 eth0   00:50:56:90:88:37  192.168.1.15 MTU:1500
 eth0   00:50:56:90:E1:2E  25.10.100.15 MTU:1500

Please help to get this请帮助得到这个

Thanks in advance提前致谢

You can use awk and set the record separator to an empty line, for example this您可以使用awk并将记录分隔符设置为空行,例如

/sbin/ifconfig  | awk -v RS='' '{print $14}'

will print将打印

MTU:1500
MTU:1500

so just pick the fields you want.所以只需选择您想要的字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM