[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: executing udev rules on _un_plug



crank@got.net (i'll teach you to turn away.) writes:

>Cameron Hutchison <lists@xdna.net> wrote:
>CH> How can I write a udev rule to be run/matched when a device is
>CH> unplugged?
>CH> 
>CH> I have a 3G modem that I wrote a rule for to run "ifup ppp0" when the
>CH> modem is plugged in. I would like to have "ifdown ppp0" be automatically
>CH> run when the modem is unplugged.

>	when i was using a modem, i used a cronjob that checked for 
>/var/run/ppp0.pid. when it's not detected, you can have it execute "ifdown 
>ppp0".

Thanks, but unfortunately, a cron job is not responsive enough for me,
as I want to be able to unplug the modem and plug it back it and have
that work.

I found the issue(s) in the end. Udev does support the action "remove",
but you cannot use all the match rules you might use on an add event. I
guess that this is because the device is no longer there so the sysfs
attributes are gone. Once I tweaked my rules I got half way there.

The other half way there was realisin that there was no remove event
generated for ttyUSB0 - I assume that it is because the device is still
in use just at that time. Thankfully the modem also generates events
for ttyUSB1 and ttyUSB2, so I could trigger the removal off one of those.



Reply to: