Hello,

I'm trying to use udev to automatically mount and unmount USB hard
drives and flash drives on a system running SLES 10. I've written a
rule that calls a script that I've also written.

***************************Rule: 86-
mount.rules*********************************

SUBSYSTEM=="block", BUS=="usb", DRIVER=="usb-storage", run+="/root/
testudevmount.sh /dev/sdb1"

*********************************end
rule******************************************

*********************Script: /root/
testudevmount.sh****************************

#!/bin/bash

echo "In script..." >> /root/udevlog.txt
echo $ACTION >> /root/udevlog.txt
echo $ID_FS_UUID >> /root/udevlog.txt
echo $1 >> /root/udevlog.txt

if [ "$ACTION" = "add" ] && [ "$ID_FS_UUID" ]
then
mkdir /media/USB-$ID_FS_UUID
mount /dev/disk/by-uuid/$ID_FS_UUID /media/USB-$ID_FS_UUID
fi

if [ "$ACTION" = "remove" ]
then
umount -l $1 >> /root/udevlog.txt 2>> /root/udevlog.txt || { echo "it
failed" >> /root/udevlog.txt}
#rmdir /media/USB-$ID_FS_UUID
fi

********************************end
script*********************************

My problem? The script works beautifully when a device is added.
However, it seems not to even get called when a device is added! The
log files show it being run for adds, but never for removes. The rule
should work for both, right??

The permissions on both the log file and the script are set to 777, so
I know that's not the problem. I've tried removing all identifiers
from the rule other than SUBSYSTEM=="block" and I still couldn't get
it to be called. The reason why /dev/sdb1 is hard-coded into the rule
is to rule out the possibility that the problem lay in the fact that
$ID_FS_UUID only gets set on add actions and not remove actions (which
I do not know to be the case). Ideally, I'd like to base my umount on
the mount point, so "/media/USB-$ID_FS_UUID" but I don't know if
$ID_FS_UUID gets set for remove actions or not.

....although right now it seems the script just doesn't exist for
remove?

I've also tried mounting the drive, then changing the name of the rule
to 04-mount.rules (which would make it be the first thing called) and
unplugging the drive, in case somewhere in the earlier rules there was
a RUN:=, but the script still didn't get called.

Using HAL to manage the devices works great, but only when someone's
logged into a GNOME session, and I need a solution that will work on a
headless system (thus udev).

Any suggestions would be greatly appreciated, as I'm basically at my
wits' end here.

Thanks!
-Elizabeth