Shell Goodies: Fetching NIC Interfaces with carrier without SED/AWK

  |   Source

As I'm rewriting some parts of the dhcp boot mechanism of live-boot, I needed the possibiility to fetch network interfaces, without the use of SED/AWK or whatever could help to parse the "ip -oneline link show" output.
As we somehow don't have sed or awk in our initramfs tools, I scribbled this:

#!/bin/sh
for device in /sys/class/net/* ; do
if [ -f "$device/carrier" ]; then
carrier=$(cat "$device/carrier" 2> /dev/null)
if [ "$carrier" = "1" ]; then
devicename=basename $device
if [ "$devicename" != "lo" ]; then
interface=cat $device/address
echo "$carrier of $devicename ($interface) is up"
fi
fi
fi
done