Can't get figure out how to use udev to launch scripts!

Problem

I’m usually comfortable around my system but I’ve come across a problem that I just can’t figure out. I have a server which runs headless that handles a samba share for the house. The only issue I have is that my brother occasionally unplugs the device. At first I just used to use an fstab entry but that only helps at boot time and isn’t ideal as the system is occasionally booted without the hard drive. My idea is now to launch a script using udev rules mount the drive. I’ve been running into issues and have reduced my problem to as basic a form as is possible and am now testing it on my own system and I still can’t solve it.

My attempt

My first step was to create the file /etc/udev/rules.d/03-mountNex.rules:

ERNEL=="sdc", ACTION=="add", RUN+="/home/daniel/script"

This should launch the script “/home/daniel/script” when I plug in a third hard drive.

The script itself is for now rudimentary:

#! /usr/bin/sh
/usr/bin/dolphin

The script just opens up an instance of dolphin. Nothing fancy.

I now restart my computer with the device not plugged in. Login in and then plug the device in.

Some other useful info is my permissions on the udev file and script:

daniel@linux-w365:/etc/udev/rules.d> ls -l
total 292
-rw-r--r-- 1 root root     57 Jan  5 16:36 03-mountNex.rules
........
ls -l                                                                                                           
total 17400                                                                                                                          
........
-rwxr-xr-x  1 daniel users          32 Jan  5 16:28 script
........

Intended Result

When I plug the device in then dolphin should launch

Actual Result

Absolutely nothing happens except the normal KDE dialog pop-ups asking what I want to do with the drive.

Suspected issue

Something to do with permissions but I’m not sure.

System Info

openSUSE 12.2 with KR49 repo.

Thanks a ton for any help you can provide.

You have a rather extensive description, but I am afraid I still am missing something.

You talk about a headless system. But then you talk about having KDE and starting Dolphin. Can you explain.

Apart from this, it seems that you want to run a script owned by an end-user on instigation of udev, which is of coourse running as root. Thus the end-user script would run as root!. Potentialy opening your system forr everyything. I would not bbe amazed that something is ptotecting the system from this behaviour.

BTW, a similar “problem” in my environment is a system that mounts an NFS file system where the NFS server is not always available. Thus root has a cron entry that (every five minutes) that checks if it is mounted and when not, tries it. I expect that one can do similar with a file sysem mount on a local disk. I see also the possibility here to have an fstab entry using mount-by-id/label/uuid, thus when another disk is conected, no mount takes place.

BTW2. When you want a rudimentary script only to check if the script runs, why such starting of a big program. Just do

echo "udev script test: $(date)" >/tmp/udevcheck

Apart from this, it seems that you want to run a script owned by an end-user on instigation of udev, which is of coourse running as root. Thus the end-user script would run as root!. Potentialy opening your system forr everyything. I would not bbe amazed that something is ptotecting the system from this behaviour.

…and because of this, it will also fail to launch dolphin when root does not own the X-session.

Have you considered automount? Or do you need to do more than just mounting it?

Oh yes, the whole idea is full of misunderstndings.

This is typicaly something that is to be aranged by a system manager, not an end-user. Thus no end-user should be involved in the solution. The script must be owned by root and in a proper place (e.g. /root/bin). And of course the script should not try to open windows on any end-user GUI session that happens to be open or active
.

Hear, hear. +What the others wrote.