:: Re: [DNG] an alternative to poetter…
Top Pagina
Delete this message
Reply to this message
Auteur: Dr. Nikolaus Klepp
Datum:  
Aan: dng
Onderwerp: Re: [DNG] an alternative to poettering's ifplugd
Hi!

Anno domini 2019 Mon, 18 Mar 18:37:37 +0100
aitor_czr scripsit:
> Hi all,
>
> On 17/3/19 13:45, aitor_czr wrote:
> >
> > I'm also working on an alternative to poettering's ifplugd for the
> > automatically wired connect option of simple-netaid.
> >
> > Aitor.
> >
> Here you are the code:
>
> gnuinos.org/examples/netproc/main.c
>
> Install the libiw-dev and ethtool packages, and build the file:
>
> gcc main.c -liw -o main
>
> and run it in the command line:
>
> $ ./main
>
> The output will be:
>
> The wire is PLUGGED/UNPLUGGED
>
> The unplug event is detected inmediatly, but the unplug event takes a
> few seconds. It's working for me.
>
> I need testers.
>
> Thanks in advance :)
>
> Aitor.
>
>
>
>


You might call me ignorant, but with bash this can be done a bit simpler (this is from my solution to the detect-if-kable-present-while-booting-problem) :-)

#!/bin/bash

while sleep 1; do
    for i in /sys/class/net/eth*; do 
        VAR=$(basename $i)
        VAL=$(sed -n 's/0/UN/p' $i/carrier)PLUGGED
        if [ "${!VAR}" != "$VAL" ]; then
            echo $VAR $VAL
            declare $VAR=$VAL
        fi
    done
done



Nik

--
Please do not email me anything that you are not comfortable also sharing with the NSA, CIA ...