After getting my 3g-modem to work in Arch Linux I wanted to eliminate some manual labour required in the process. Hence I needed to create an udev rule. After some trial and error I came up with the following rule named 11-my-rule.rules which I placed at /etc/udev/rules.d/:
# start at sdb to ignore the system hard drive KERNEL!="sd[b-z]*", GOTO="my_media_automount_end" # run the script and create a testdir to verify the rule works ACTION=="add", RUN+="/myscript.sh", RUN+="/bin/mkdir -p '/media/pendrive'" #remove the testfolder on removal of usb ACTION=="remove", RUN+="/bin/rm -R '/media/pendrive'" # exit LABEL="my_media_automount_end"
My testscript which is meant to be ran is as follows:
#!/bin/bash DISPLAY=:0 xterm
Which displays xterminal. I have tested the script itself and it works. Also the second RUN+ that creates the test-directory works as well. Hence I am at a loss just what am I doing wrong.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
@EightBitTony may be right. The udev rules are executed as the root user. So in addition to specifying the DISPLAY, you need to grant this root user access to your X session.
This can be achived by finding the corresponding authority file and exporting it as XAUTHORITY. echo $XAUTHORITY from a terminal emulator can tell you, where it is.
Using a display manager, the location is likely to change on each login. Alternatively, you can invoke xhost + from your x session, granting all other users access to this session. xhost - would close this again. Be reminded, that this also enables remote users to access the session using a TCP port.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0