On 15.08.17 09:29, Greg Wooledge wrote: > wooledg:~$ netstat -in > Kernel Interface table > Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg > eth0 1500 8254258 0 0 0 7682795 0 0 0 > BMRU > lo 65536 579959 0 0 0 579959 0 0 0 LRU > was compared with:
> wooledg:~$ ip link > 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode > DEFAULT group default qlen 1 > link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 > 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP > mode DEFAULT group default qlen 1000 > link/ether a0:8c:fd:c3:89:e0 brd ff:ff:ff:ff:ff:ff > > Parsing the interface names out of THAT is significantly harder. Yes, true, for a human that's indisputable. However, a first off-the-cuff quickie does the trick machine-wise: $ gawk '/^[0-9]:/ {print $2}' /tmp/mail lo: eth0: So the situation is eminently remediable, I figure. Obviously the first-cut snippet can easily be made more robust, but with known input, there is no immediate need. > The real tragedy is the missed opportunity. Linux developers wrote > iproute2 from scratch, but they failed to add any kind of user-specified > output format (cf. ps h -o ppid, find -printf %h, etc.), or to sit down > and THINK about how the user interface should be designed. Instead of > a clean, friendly, consistent, useful new tool we just got this weird > monstrosity that feels like someone decided to change things just because > they were bored one day, without any rhyme or reason or plan. If the output remains unchanged, then a bit of awk¹ can easily extract items of interest. Scripts break very badly, though, if the output format is fiddled with after it has been in the wild for any extended period. But I'm drawn to the familiar per-interface ordered reporting of: $ ifconfig -a eth0 Link encap:Ethernet HWaddr 00:27:21:a0:4f:1e inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: ee81::233:17ff:fea3:2f5e/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:573689 errors:0 dropped:0 overruns:0 frame:0 TX packets:338733 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:800824302 (763.7 MiB) TX bytes:27874966 (26.5 MiB) Interrupt:23 Base address:0xee00 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:12551 errors:0 dropped:0 overruns:0 frame:0 TX packets:12551 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:3328348 (3.1 MiB) TX bytes:3328348 (3.1 MiB) That's highly amenable to both human and machine parsing, I submit. Erik ¹ Yes, I've heard rumours of other text processing languages arising in the latter years of the last millennium, but they're probably a passing fad, I figure.