0

This question already has an answer here:

I want to learn more about udev rules, so I implemented a simple one, but I doesn't work:

/etc/udev/rules.d:

KERNEL=="sdb1"
ACTION=="add"

RUN+="~/test/exe.sh"

~/test/exe.sh:

#!/bin/bash
echo "USB plugged in" > ~/test/showup.txt

the .sh file is executable, and I checked the flash drive's name via lsblk. It is called sdb and has a sdb1 partition.

I already looked up different tutorials, but can't find my mistake. I use Arch Linux in case that matters.

marked as duplicate by jasonwryan, Stephen Rauch, Rui F Ribeiro, Anthon, jimmij Jul 23 '17 at 8:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    Aside from any other issue, udev knows nothing about ~... – jasonwryan Jul 22 '17 at 22:53
1

udev rules execute by root.

The RUN+="~/test/exe.sh" equals "/root/test/exe.sh", but udev rules seems not recognize the "~"; modify the path will solve this issue.

put your script such in "/usr/bin/exe.sh" might be better.

  • 1
    Or given that it's run as root he can just use the absolute original path instead. – Cory T Jul 23 '17 at 1:16
  • 1
    Agreed, your advice also solve this question. – Wally Jul 23 '17 at 8:05
  • I noticed it is also working in my home directory if I use the absolute path, but I have to call the file exe.sh even though I specify it in the udev rule as exe. Why is it automatically adding the suffix .sh to the file it looks for? Or do I understand something wrong? – Jonas Jul 23 '17 at 20:24

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