0

I become mad, I don't understand why my script don't want to be launch by udev. I have the latest raspian (wheezy) My rule (in /etc/udev/rules.d/) :

root@raspberrypi:/etc/udev/rules.d# cat 10-box.rules 
ACTION=="add", KERNEL=="sd*1", SUBSYSTEM=="block", RUN+="/usr/bin/test.sh"

Now my script :

root@raspberrypi:/usr/bin# ls -al test.sh
-rwxr-xr-x 1 root root 27 Aug 22 11:06 test.sh

root@raspberrypi:/usr/bin# cat test.sh
#!/bin/sh
echo "YOU HAVE ADD A USB KEY"

The device (usb key) :

root@raspberrypi:/usr/bin# udevadm info -an /dev/sda1

..
looking at device '/devices/platform/bcm2708_usb/usb1/1-1/1-1.4/1-1.4:1.0/host1/target1:0:0/1:0:0:0/block/sda/sda1':
KERNEL=="sda1"
SUBSYSTEM=="block"
DRIVER==""
ATTR{ro}=="0"
ATTR{size}=="1031352"
ATTR{stat}=="     159        0     1280      180        0        0        0        0        0      180      180"
ATTR{partition}=="1"
ATTR{start}=="32"
ATTR{discard_alignment}=="0"
ATTR{alignment_offset}=="0"
ATTR{inflight}=="       0        0"

looking at parent device '/devices/platform/bcm2708_usb/usb1/1-1/1-1.4/1-1.4:1.0/host1/target1:0:0/1:0:0:0/block/sda':
KERNELS=="sda"
SUBSYSTEMS=="block"
....

Why nothing append to stdout when I insert my key ???

Regards

1 Answer 1

2

Probably because the script does not have a stdout.

Try this instead (where pi is the user who should be told)

#!/bin/sh
write pi <<EOM
YOU HAVE ADDED A USB KEY
EOM
1
  • 1
    It's not that it doesn't have a stdout, it's that it's not been redirected where you want it. So you should be able to, e.g., exec &> /dev/console -- that's a bashism though (it redirects stdout and stderr), so use #!/bin/bash. Beware that joan's version will write to user pi, mine only redirects to the system console, which you won't see in the GUI.
    – goldilocks
    Commented Aug 22, 2015 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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