Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

udev won't execute rule properly

Tags:

rsync

umount

udev

udev does not run my bash script properly.

Heres my rule:

ACTION=="add", KERNEL=="sd*1", SUBSYSTEM=="block", ATTRS{idVendor}=="0930", ATTRS{idProduct}=="6544", RUN="/usr/local/bin/usb-bmw-in"    
ACTION=="remove", KERNEL=="sd*1", SUBSYSTEM=="block", ATTRS{idVendor}=="0930", ATTRS{idProduct}=="6544", RUN="/usr/local/bin/usb-bmw-out"

And here is the script that gets executed:

#!/bin/bash
echo timer > /sys/class/leds/led1/trigger
rsync --delete-after -c --preallocate -r /media/NAS/Sync/Musik/BMW/ /media/24366EC6366E9916/
umount /dev/sdc1
echo default-on > /sys/class/leds/led0/trigger
echo none > /sys/class/leds/led1/trigger

The script should light up a red led, indicating that its working. Then it should copy my car playlist to the usb stick and unmount the device.

When it's done, it should light up a green led and turn off the red one.

The red led lights up properly, the rsync command gets fired as well, but thats it. The red LED is still on, the device is still mounted and the green led hasnt been turned on.

When I run the script manually its working fine.

like image 344
Unkn0wn Avatar asked Apr 09 '26 17:04

Unkn0wn


1 Answers

Actually made it working by moving the two echo command at the bottom above the umount command and relaunched the script in a background shell with setsid as explained by the user "Alives" on stackexchange:

https://unix.stackexchange.com/a/79545

like image 152
Unkn0wn Avatar answered Apr 12 '26 20:04

Unkn0wn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!