[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: udev rule writing help needed

On Sun, 10 Jun 2007 19:30:16 +0200, Don Hayward wrote:

> I have a new Seagate FreeAgent usb hard drive.  After install, it spins
> down and when one tries to write to it, it gets marked read only. This
> can be prevented by running the following command line:
> echo 1 > /sys/class/scsi_disk/14\:0\:0\:0/allow_restart
> where this bit                ^^^^^^^^^^^ varies with each connection.
> I'd like to get udev to set this for me, so I tried the following rule:
> SYSFS{model}=="FreeAgentDesktop",RUN+="/bin/echo 1 >
> /sys/class/scsi_disk/%k/allow_restart"
> It doesn't work.  Allow_restart is always 0 after a connection.
> I've also tried:
> SYSFS{model}=="FreeAgentDesktop",RUN+="/bin/echo 1 >
> /sys/class/scsi_disk/%b/allow_restart"
> SYSFS{model}=="FreeAgentDesktop",RUN+="/bin/echo 1 >
> '/sys/class/scsi_disk/%k/allow_restart'"
> SYSFS{model}=="FreeAgentDesktop",RUN+="/bin/echo 1 >
> '/sys/class/scsi_disk/%b/allow_restart'"
> because I'm confused about 1) which string substitution holds the
> identifier I need, and 2) the need for quoting or escaping the ':' in
> the line.
> udevtest shows this:
> parse_file: reading '/etc/udev/rules.d/10-local.rules' as rules file and
> this
> main: run: 'socket:/org/freedesktop/hal/udev_event' so my rule seems to
> be picked up.
> udevinfo -a -p /sys/block/sdd
> shows:
>    looking at parent device
>    '/devices/pci0000:00/0000:00:06.0/0000:02:0b.2/usb5/5-3/5-3:1.0/
>      KERNELS=="14:0:0:0"
>     ATTRS{model}=="FreeAgentDesktop"
> ...
> So my questions are:
> 1) what string substitution do I use to get the needed bit into my
> command? 2) do I need quoting in the rule?
> 3) can this work anyway?
> Thanks for any help.
> Don
I have found the rules easy to write and writing the executables called 
tricky.  This following is a kludge: with probably some over the top and 
uneccessary parts.  It is adapted from a udev triggered script I use to 
get my scripts to run in xterminals - perhaps that will help your script 
to work.  And perhaps someone here can help clean it up.

First put your line in a script (I am assuming you need to run the 
command as root - in which case you will need to set up sudo to work for 

sudo echo 1 > /sys/class/scsi_disk/14\:0\:0\:0/allow_restart
#Delete the following 2 lines once everything is working
echo 'udev executed script finished: Press enter.'
read ARG

The effect of the last two lines is to give you a chance to see any 
relevant output for troubleshooting.  Call the script, say, 
scsiScriptForUdev.  Test it, make it executable and save it in /usr/

if [ "$ACTION" != 'add' ] ; then
export PATH=/bin:/sbin:/usr/bin:/usr/sbin
X11User=`who | grep $LocalDisplay | sed -n 1p | cut -f 1 -d ' '`
Command='sudo xterm -e scsiScriptForUdev'
export DISPLAY=$LocalDisplay
nice -n 19 su $X11User -c "$Command &> /tmp/udevScriptErrorOutput.txt" & 

Seems crazy and I am sure there is a neater way to do it - but perhaps 
with the xterm output and the output in the /tmp/ text file you will have 
more information to work with.

If you do manage to get it working and/or optimise it let us know.


Reply to: