Theo de Raadt writes:
> > > + for _hn in /etc/hostname.??:??:??:??:??:??; do
> > > +         _mac=`echo $_hn | cut -c 15-31`

_mac=${_hn#/etc/hostname.}

> > > +         _if=`ifconfig | grep -B 1 $_mac | head -n 1 | awk -F ": " 
> > > '{print $1}'`

mac2dev() {
        # This got long
        ifconfig | while IFS= read _line; do
                if [[ "$_line" = [a-z]!(\ *):* ]]; then
                        _dev=${_line%%:*}
                elif [[ "$_line" = *lladdr*$1* && $_dev != vlan* ]]; then
                        echo $_dev
                fi
        done
}

_if=$(mac2dev "$_mac") # or just _if=$(mac2dev ${_hn#*.})

IFS needs to be cleared for read otherwise initial whitespace is
stripped from _line.

Note that the vlan devices need to be excluded. Are there other
circumstances which could confuse this in ifconfig's output?

It could probably return immediately after printing.

Matthew

Reply via email to