0

i wrote a udev rule and placed it in /etc/udev/rules/90-wifi.rules

ACTION=="add", SUBSYSTEM=="usb", DRIVER=="usb", RUN+="sh /usr/local/bin/setup_wifi_wrapper.sh"

It should run on every inserted usb device.

It should start the script /usr/local/bin/setup_wifi_wrapper.sh

#!/bin/bash
/usr/local/bin/start_wifi.sh & disown

And that should start /usr/local/bin/start_wifi.sh

#!/bin/bash

sudo systemctl start hostapd
sudo ifup br0
sudo systemctl restart dnsmasq
touch /home/user/started

But it does not... The scripts are all executable and I can start them from command line and they do what they are supposed to do. I tried having them in differente locations, started in the home folder moved them to usr/local/bin. Made the wrapper with disown for background processes but still no results. Does anybody have an idea?

Thanks in advance

1

From the udev man page for RUN:

Execute an external program specified as the assigned value. If no absolute path is given, the program is expected to live in /lib/udev; otherwise, the absolute path must be specified.

sh is not in /lib/udev.

Furthermore, by beginning with sh the script is run by the Sh interpreter. However, from the command line likely no interpreter was given, so the #!/bin/bash line would be used to select Bash.

The disown is Bash specific. Therefore just remove the leading sh from this part of the rule:

RUN+="/usr/local/bin/setup_wifi_wrapper.sh"
  • Thank you, but sadly after changing the run part. The script is still not executed – Lenny Sep 9 at 7:56
  • Run sudo udevadm control -R to reload the rules and try again. Does only the touch work, or does nothing happen at all? Is there a specific USB device you want to match? – Martin Thornton Sep 9 at 10:23
  • Still to no avail, i did use the reload before already. And no i would be happy with any usb device. I don't really care which one it is. Therefore it should be fairly generalized. But even with a more specilized ATTR() the rule does not trigger – Lenny Sep 9 at 10:58
  • I tried to simplifiy the rule. So I only have a touch in the wrapper script. But this is not executed as well. Therefore it seems, that the problem is, that the rule is never invoked – Lenny Sep 9 at 12:38
  • You solution actually worked... The problem was a minor typo on my side to get it completly working. Thank you – Lenny Sep 14 at 14:39
0

change the udev-rule

ACTION=="add", SUBSYSTEMS=="usb", DRIVERS=="usb", RUN+="/bin/sh /usr/local/bin/setup_wifi_wrapper.sh"

I would avoid the RUN+ Key.

And your the skript

 #!/bin/sh
/bin/sleep 10 
systemctl start hostapd &&
ifup br0 &&
systemctl restart dnsmasq &&
touch /home/user/started

The sequence only work if every command is successful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.