I'm having trouble getting a script run by udev to run in the background on usb insert.
My udev rule seems to work, since it definitely calls the script, but no matter what I do, I can't get bash script to run in the background, so it blocks.
For Reference:
My udev rule:
ATTRS{idVendor}=="125f", ATTRS{idProduct}=="db8a", SYMLINK+="usb/adata%n", ENV{XAUTHORITY}="/home/abe/.Xauthority", ENV{DISPLAY}=":0", OWNER="abe", RUN+="/home/abe/bin/usb-adata_udev.sh"
My bash script:
#!/bin/bash
if [[ $ACTION == "add" ]]; then
# I've tried many variations on this, none seem to work
(su abe /bin/bash -c "/home/abe/Documents/Programs/USB\ Sync/usb-in.sh") &
fi
if [[ $ACTION == "remove" ]]; then
/home/abe/Documents/Programs/USB\ Sync/usb-out.sh &
fi
the background script:
#!/bin/bash
#echo $ACTION > "/home/abe/Desktop/test.txt"
if [[ ! -d "/media/abe/ABE" ]]; then
# for testing
sleep 10
#udisksctl mount -b /dev/usb/adata1 &> "/home/abe/Desktop/test.txt"
#rsync --update /media/abe/ABE/Files/db.kdbx /home/abe/Documents/db.kdbx
echo "FINISHED" >> "/home/abe/Desktop/test.txt"
fi
The usb is doesn't get mounted by nautilus until the 10 seconds are done, and the udisksctl command gives me the error Error looking up object for device /dev/usb/adata1
when uncommented, which makes me think that the udev rule hasn't even finished making the symlinks.
Note that the script works just fine when I run it from my terminal and not udev
&
inRUN+=
, and the script runs anohup bash -c "stuff" & disown
, yet the commandstuff
dies immediately, if at all started. – Gauthier Oct 14 '19 at 09:43udev
changed much lately in these years. Let me update my question, at least give a hint. – user.dz Oct 14 '19 at 09:57