Skip to contentSkip to conversation

RUN

DISCUSSION Adam Kane 7 participants 10 messages Jul 10, 2007 – Jul 13, 2007

lore
Share & tools
lore

Adam Kane

author
#0 lore raw

Hi list,

Is it possible to use more than one RUN+= statement in a udev line, or execute more than one thing? I am wanting to execute more than one thing upon my usb key being plugged in.

Here is what I have in udev.rules

BUS="scsi", SYSFS{model}="USB2FlashStorage", SYMLINK="usbdrive", RUN+="/bin/mount /dev/usbdrive"

The RUN+ statement is mounting the drive to /media/usbdrive, as specified in the /etc/fstab. I would like to to also run "/bin/sh /media/usbdrive/test.sh"

I have tried the following with no success:

BUS="scsi", SYSFS{model}="USB2FlashStorage", SYMLINK="usbdrive", RUN+="/bin/mount /dev/usbdrive ; /bin/sh /media/usbdrive/test.sh"

BUS="scsi", SYSFS{model}="USB2FlashStorage", SYMLINK="usbdrive", RUN+="/bin/mount /dev/usbdrive && /bin/sh /media/usbdrive/test.sh"

BUS="scsi", SYSFS{model}="USB2FlashStorage", SYMLINK="usbdrive", RUN+="/bin/mount /dev/usbdrive", RUN+="/bin/sh /media/usbdrive/test.sh"

Hope this makes sense.

Thanks in advance,

Adam Kane

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#1 lore raw

Adam Kane wrote on 10-07-07 22:32:

Quoted 21 lines

Hi list,

Is it possible to use more than one RUN+= statement in a udev line, or execute more than one thing? I am wanting to execute more than one thing upon my usb key being plugged in.

Here is what I have in udev.rules

BUS="scsi", SYSFS{model}="USB2FlashStorage", SYMLINK="usbdrive", RUN+="/bin/mount /dev/usbdrive"

The RUN+ statement is mounting the drive to /media/usbdrive, as specified in the /etc/fstab. I would like to to also run "/bin/sh /media/usbdrive/test.sh"

I have tried the following with no success:

BUS="scsi", SYSFS{model}="USB2FlashStorage", SYMLINK="usbdrive", RUN+="/bin/mount /dev/usbdrive ; /bin/sh /media/usbdrive/test.sh"

Quoted 6 lines

BUS="scsi", SYSFS{model}="USB2FlashStorage", SYMLINK="usbdrive", RUN+="/bin/mount /dev/usbdrive && /bin/sh /media/usbdrive/test.sh"

BUS="scsi", SYSFS{model}="USB2FlashStorage", SYMLINK="usbdrive", RUN+="/bin/mount /dev/usbdrive", RUN+="/bin/sh /media/usbdrive/test.sh"

Something like RUN+="eval bin/mount /dev/usbdrive"; /media/usbdrive/test.sh"? Or put all commands in one script and run that:
RUN+="mount_and_test.sh"

Quoted 1 line

Adam Kane

bjd

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

author
#2 lore raw
In reply to Adam Kane

Using the ; separator will not work. I tried adding eval, and still no luck.

Putting the commands in one script is not feasible as I do not want the script to reside on the machine, instead on the thumb drive. Does that make sense?

Adam

Quoted 35 lines · Bauke Jan Douma

Adam Kane wrote on 10-07-07 22:32:

Quoted 21 lines

Hi list,

Is it possible to use more than one RUN+= statement in a udev line, or execute more than one thing? I am wanting to execute more than one thing upon my usb key being plugged in.

Here is what I have in udev.rules

BUS="scsi", SYSFS{model}="USB2FlashStorage", SYMLINK="usbdrive", RUN+="/bin/mount /dev/usbdrive"

The RUN+ statement is mounting the drive to /media/usbdrive, as specified in the /etc/fstab. I would like to to also run "/bin/sh /media/usbdrive/test.sh"

I have tried the following with no success:

BUS="scsi", SYSFS{model}="USB2FlashStorage", SYMLINK="usbdrive", RUN+="/bin/mount /dev/usbdrive ; /bin/sh /media/usbdrive/test.sh"

Quoted 6 lines

BUS="scsi", SYSFS{model}="USB2FlashStorage", SYMLINK="usbdrive", RUN+="/bin/mount /dev/usbdrive && /bin/sh /media/usbdrive/test.sh"

BUS="scsi", SYSFS{model}="USB2FlashStorage", SYMLINK="usbdrive", RUN+="/bin/mount /dev/usbdrive", RUN+="/bin/sh /media/usbdrive/test.sh"

Something like RUN+="eval bin/mount /dev/usbdrive"; /media/usbdrive/test.sh"?
Or put all commands in one script and run that:
RUN+="mount_and_test.sh"

Quoted 4 lines
Quoted 1 line

Adam Kane

bjd

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#3 lore raw
In reply to Adam Kane
Quoted 43 lines · Adam Kane

Using the ; separator will not work. I tried adding eval, and still no luck.

Putting the commands in one script is not feasible as I do not want the script to reside on the machine, instead on the thumb drive. Does that make sense?

Adam

Quoted 33 lines · Bauke Jan Douma

Adam Kane wrote on 10-07-07 22:32:

Quoted 21 lines

Hi list,

Is it possible to use more than one RUN+= statement in a udev line, or execute more than one thing? I am wanting to execute more than one thing upon my usb key being plugged in.

Here is what I have in udev.rules

BUS="scsi", SYSFS{model}="USB2FlashStorage", SYMLINK="usbdrive", RUN+="/bin/mount /dev/usbdrive"

The RUN+ statement is mounting the drive to /media/usbdrive, as specified in the /etc/fstab. I would like to to also run "/bin/sh /media/usbdrive/test.sh"

I have tried the following with no success:

BUS="scsi", SYSFS{model}="USB2FlashStorage", SYMLINK="usbdrive", RUN+="/bin/mount /dev/usbdrive ; /bin/sh /media/usbdrive/test.sh"

Quoted 6 lines

BUS="scsi", SYSFS{model}="USB2FlashStorage", SYMLINK="usbdrive", RUN+="/bin/mount /dev/usbdrive && /bin/sh /media/usbdrive/test.sh"

BUS="scsi", SYSFS{model}="USB2FlashStorage", SYMLINK="usbdrive", RUN+="/bin/mount /dev/usbdrive", RUN+="/bin/sh /media/usbdrive/test.sh"

Something like RUN+="eval bin/mount /dev/usbdrive"; /media/usbdrive/test.sh"?
Or put all commands in one script and run that:
RUN+="mount_and_test.sh"

Today you can have only one RUN key, it will change some day, but I never got to finish the smarter rule parsing which will allow any number of keys in a rule.

You need to do:
RUN+="/bin/sh -c '/program1; /program2'"
for now.

Kay

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#4 lore raw
In reply to Adam Kane
Quoted 7 lines

Today you can have only one RUN key, it will change some day, but I never got to finish the smarter rule parsing which will allow any number of keys in a rule.

You need to do:

   RUN+="/bin/sh -c '/program1; /program2'"

for now.

I have misunderstood either the poster's question or the paragraph in "man udev" discussing the RUN key:

----excerpt----
RUN

Add a program to the list of programs to be executed for a specific
device. This can only be used for very short running tasks. Running an event process for a long period of time may block all further events for this or a dependent device. Long running tasks need to be immediately detached from the event process itself.

----excerpt----

For example, this works:

SUBSYSTEM="*", RUN+="/root/udev-catch-remove"
ENV{DEVNAME}="/dev/foobar", RUN+="/path/to/prog"

Is this only working because the match keys are different?

Regards,
Richard

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#5 lore raw
In reply to Adam Kane
Quoted 20 lines · Richard Michael
Quoted 7 lines

Today you can have only one RUN key, it will change some day, but I never got to finish the smarter rule parsing which will allow any number of keys in a rule.

You need to do:

   RUN+="/bin/sh -c '/program1; /program2'"

for now.

I have misunderstood either the poster's question or the paragraph in "man udev" discussing the RUN key:

----excerpt----
RUN

Add a program to the list of programs to be executed for a specific
device. This can only be used for very short running tasks. Running an event process for a long period of time may block all further events for this or a dependent device. Long running tasks need to be immediately detached from the event process itself.

Quoted 8 lines

----excerpt----

For example, this works:

SUBSYSTEM="*", RUN+="/root/udev-catch-remove"
ENV{DEVNAME}="/dev/foobar", RUN+="/path/to/prog"

Is this only working because the match keys are different?

These are two rules with independent RUN keys, right?

The first on runs for _every_ event as the SUBSYSTEM match doesn't do anything. The second may run when the env matches, but $DEVNAME is usually not available at the time of rule processing. You can have any number of rules with _one_ RUN key per rule and they will all be executed.

The question was how to run two programs from a _single_ rule. The obvious solution would be to specify two RUN keys, but that doesn't work with todays in-memory rule presentation. It will change when I find the time to work on that.

Thanks,
Kay

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#6 lore raw
In reply to Adam Kane

-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160

Quoted 1 line · Kay Sievers

The question was how to run two programs from a _single_ rule.

Would duplicate rules (with the same criteria) work? I.e., something like:

BUS="scsi", ATTRS{model}="USB2FlashStorage", SYMLINK+="usbdrive", RUN+="/bin/mount /dev/usbdrive"
BUS="scsi", ATTRS{model}="USB2FlashStorage", RUN+="/bin/sh /media/usbdrive/test.sh"

(Where I've fixed the keys to match what udev >= 098 expects.)

Assuming these fire in the same order as they're in the rules file (and multiple rules are allowed to have the same criteria), it should work for what Adam needs (I think).
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGlDxgS5vET1Wea5wRAx/eAJ4o52jmBleuTl6CAy05RzTg9BmvCQCg4cSH 2MSYkpd+QMggI7Uo2vhXJ84=WzoU
-----END PGP SIGNATURE-----

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#7 lore raw
In reply to Adam Kane
Quoted 6 lines · Bryan Kadzban
Quoted 1 line · Kay Sievers

The question was how to run two programs from a _single_ rule.

Would duplicate rules (with the same criteria) work? I.e., something like:

Quoted 7 lines

BUS=="scsi", ATTRS{model}=="USB2FlashStorage", SYMLINK+="usbdrive", RUN+="/bin/mount /dev/usbdrive"
BUS=="scsi", ATTRS{model}=="USB2FlashStorage", RUN+="/bin/sh /media/usbdrive/test.sh"

(Where I've fixed the keys to match what udev >= 098 expects.)

You could also use a GOTO/LABEL combination

BUS!="scsi", GOTO="usbdrive_end" ATTRS{model}!="USB2FlashStorage", GOTO="usbdrive_end"

SYMLINK+="usbdrive"
RUN+="/bin/mount /dev/usbdrive"
RUN+="/bin/sh /media/usbdrive/test.sh"

LABEL="usbdrive_end"

Scott

Signature · 3 lines
Scott James Remnant
Ubuntu Development Manager
[email protected]

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#8 lore raw
In reply to Adam Kane
Quoted 8 lines

You can have any number of rules with _one_ RUN key per rule and they will all be executed.

The question was how to run two programs from a _single_ rule. The obvious solution would be to specify two RUN keys, but that doesn't work with todays in-memory rule presentation. It will change when I find the time to work on that.

That clarifies it, thanks.

Perhaps the man page could indicate:

RUN

If more than one program must be run for an event, a rule with one RUN
key must be written for each program. For example, to run three programs, write three rules with identical match keys, each running one of the three programs.

Does that decribe the situation accurately?

Richard

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

author
#9 lore raw
In reply to Adam Kane
Quoted 50 lines · Kay Sievers
Quoted 32 lines · Adam Kane

Using the ; separator will not work. I tried adding eval, and still no luck.

Putting the commands in one script is not feasible as I do not want the script to reside on the machine, instead on the thumb drive. Does that make sense?

Adam

Quoted 22 lines · Bauke Jan Douma

Adam Kane wrote on 10-07-07 22:32:

Quoted 21 lines

Hi list,

Is it possible to use more than one RUN+= statement in a udev line, or execute more than one thing? I am wanting to execute more than one thing upon my usb key being plugged in.

Here is what I have in udev.rules

BUS="scsi", SYSFS{model}="USB2FlashStorage", SYMLINK="usbdrive", RUN+="/bin/mount /dev/usbdrive"

The RUN+ statement is mounting the drive to /media/usbdrive, as specified in the /etc/fstab. I would like to to also run "/bin/sh /media/usbdrive/test.sh"

I have tried the following with no success:

BUS="scsi", SYSFS{model}="USB2FlashStorage", SYMLINK="usbdrive", RUN+="/bin/mount /dev/usbdrive ; /bin/sh /media/usbdrive/test.sh"

Quoted 12 lines
Quoted 6 lines
Quoted 6 lines

BUS="scsi", SYSFS{model}="USB2FlashStorage", SYMLINK="usbdrive", RUN+="/bin/mount /dev/usbdrive && /bin/sh /media/usbdrive/test.sh"

BUS="scsi", SYSFS{model}="USB2FlashStorage", SYMLINK="usbdrive", RUN+="/bin/mount /dev/usbdrive", RUN+="/bin/sh

/media/usbdrive/test.sh"

Quoted 5 lines

Something like RUN+="eval bin/mount /dev/usbdrive"; /media/usbdrive/test.sh"?
Or put all commands in one script and run that:
RUN+="mount_and_test.sh"

Today you can have only one RUN key, it will change some day, but I never got to finish the smarter rule parsing which will allow any number of keys in a rule.

Quoted 5 lines

You need to do:
RUN+="/bin/sh -c '/program1; /program2'"
for now.

Kay

Thank you Kay, this solution has proved viable.

Adam

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel