1

I have some trouble with running script from udev rule. It works normal if I will run it from terminal, but one command doesn't work when udev rule run this script.

Udev rule: /etc/udev/rules.d/84-test-rule.rules

ACTION=="remove", RUN+="/bin/bash -c '/usr/bin/sblock.sh >> /home/username/udev_test_log.txt'"

Script: /usr/bin/sblock.sh

#!/bin/bash
echo Hello, its script from udev udev_test_log.txt # this line wors normal
xdg-screensaver lock # but screen not block

I expect, that my system will blocks every time I remove usb-flash (I have planned to add some properties of my usb-drive later). But after removing flash I have only line in file udev_test_log.txt.

System -- kubuntu 16.04

  • Have you made it executable? – George Udosen Apr 11 '17 at 11:42
  • Yes. And it runs -- first command of script write ine in file /home/username/udev_test_log.txt. But next command works only if launch script from terminal – Manch Apr 11 '17 at 11:48
  • Please fix the typos in your question. Is it #!/bun/bash or #!/bin/bash? If you have a shebang line (#!/bin/bash) and have made the script executable, why are you running with bash -c? More importantly, what fails? Is the echo Hello line printed? What were you expecting to happen and what actually happens? – terdon Apr 11 '17 at 11:59
  • 1
    @Manch, I expect you need to define the environment variable for display and dbus before calling xdg-screensaver. see this example askubuntu.com/a/642898/26246 – user.dz May 2 '17 at 23:38
  • 1
    Maybe it can get an answer with explanation though @DavidFoerster? It doesn't look exactly the same though the principle may be – Zanna Nov 11 '17 at 6:43

Browse other questions tagged or ask your own question.