All of lore.kernel.org
 help / color / mirror / Atom feed
* problem executing command substitution from udev rules
@ 2010-11-02  6:46 J. Bakshi
  2010-11-02  9:51 ` Andrey Borzenkov
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: J. Bakshi @ 2010-11-02  6:46 UTC (permalink / raw)
  To: linux-hotplug

Hello llist,
 
I am using notify-send in my udev rules to send desktop notification.   Here is the actual command which is working fine for me, even from the root shell.
 
 ````````````
 /bin/su `ps aux | grep startx | grep '/bin/sh' | awk '{print $1}'` -c "DISPLAY=:0.0 notify-send  "test"
 `````````````
 
the part  [ ps aux | grep startx | grep '/bin/sh' | awk '{print $1}' ] is for collecting the user-name who is running startx. 
 
now in my udev rule if I hard-coded the user name like 
 
 ```````````````
 ACTION="add", SUBSYSTEM="input", ENV{ID_CLASS}="mouse", ENV{DISPLAY}=":0.0", ENV{XAUTHORITY}="/home/user1/.Xauthority"  RUN+="/bin/su  user1 -c "DISPLAY=:0.0 notify-send "test" "
 ``````````````````````````
 
 it works well.  But if I try to add command substitution ( with in back-qoutes ) to dynamically collect the user name , it stops working. The rule is like
 
```````````````
 ACTION="add", SUBSYSTEM="input", ENV{ID_CLASS}="mouse", ENV{DISPLAY}=":0.0", ENV{XAUTHORITY}="/home/user1/.Xauthority"  RUN+="/bin/su  `ps aux | grep startx | grep '/bin/sh' | awk '{print $1}'`  -c "DISPLAY=:0.0 notify-send "test"  "
 ``````````````````````````
 
Definitely I have user1 who is using startx here. Surely the command substitution with in udev rules is not working at all. Can't understand why it fails. I would be grateful if any one point out what is missing/wrong here.
 
Thanks
 
 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: problem executing command substitution from udev rules
  2010-11-02  6:46 problem executing command substitution from udev rules J. Bakshi
@ 2010-11-02  9:51 ` Andrey Borzenkov
  2010-11-02 11:49 ` J. Bakshi
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Andrey Borzenkov @ 2010-11-02  9:51 UTC (permalink / raw)
  To: linux-hotplug

On Tue, Nov 2, 2010 at 9:34 AM, J. Bakshi <j.bakshi@unlimitedmail.org> wrote:
>  it works well.  But if I try to add command substitution ( with in back-qoutes ) to dynamically collect the user name , it stops working. The rule is like
>
> ```````````````
>  ACTION="add", SUBSYSTEM="input", ENV{ID_CLASS}="mouse", ENV{DISPLAY}=":0.0", ENV{XAUTHORITY}="/home/user1/.Xauthority"  RUN+="/bin/su  `ps aux | grep startx | grep '/bin/sh' | awk '{print $1}'`  -c "DISPLAY=:0.0 notify-send "test"  "
>  ``````````````````````````
>

I do not think udev is using shell to start external commands. You
will need to use something like

RUN+="/bin/sh -c '...'"

Quoting will quickly become unmanageable I am afraid :)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: problem executing command substitution from udev rules
  2010-11-02  6:46 problem executing command substitution from udev rules J. Bakshi
  2010-11-02  9:51 ` Andrey Borzenkov
@ 2010-11-02 11:49 ` J. Bakshi
  2010-11-03 13:17 ` Dan Nicholson
  2010-11-03 15:50 ` J. Bakshi
  3 siblings, 0 replies; 5+ messages in thread
From: J. Bakshi @ 2010-11-02 11:49 UTC (permalink / raw)
  To: linux-hotplug

On Tue, 2 Nov 2010 12:51:16 +0300
Andrey Borzenkov <arvidjaar@gmail.com> wrote:

> On Tue, Nov 2, 2010 at 9:34 AM, J. Bakshi <j.bakshi@unlimitedmail.org> wrote:
> >  it works well.  But if I try to add command substitution ( with in back-qoutes ) to dynamically collect the user name , it stops working. The rule is like
> >
> > ```````````````
> >  ACTION="add", SUBSYSTEM="input", ENV{ID_CLASS}="mouse", ENV{DISPLAY}=":0.0", ENV{XAUTHORITY}="/home/user1/.Xauthority"  RUN+="/bin/su  `ps aux | grep startx | grep '/bin/sh' | awk '{print $1}'`  -c "DISPLAY=:0.0 notify-send "test"  "
> >  ``````````````````````````
> >
> 
> I do not think udev is using shell to start external commands. You
> will need to use something like
> 
> RUN+="/bin/sh -c '...'"
> 
> Quoting will quickly become unmanageable I am afraid :)

Yes, I have tried with that but no success. I used

RUN+="/bin/sh -c '/bin/su user1 -c 'DISPLAY=:0.0 notify-send test''"

and no luck.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: problem executing command substitution from udev rules
  2010-11-02  6:46 problem executing command substitution from udev rules J. Bakshi
  2010-11-02  9:51 ` Andrey Borzenkov
  2010-11-02 11:49 ` J. Bakshi
@ 2010-11-03 13:17 ` Dan Nicholson
  2010-11-03 15:50 ` J. Bakshi
  3 siblings, 0 replies; 5+ messages in thread
From: Dan Nicholson @ 2010-11-03 13:17 UTC (permalink / raw)
  To: linux-hotplug

On Tue, Nov 2, 2010 at 4:50 AM, J. Bakshi <j.bakshi@unlimitedmail.org> wrote:
> On Tue, 2 Nov 2010 12:51:16 +0300
> Andrey Borzenkov <arvidjaar@gmail.com> wrote:
>
>> On Tue, Nov 2, 2010 at 9:34 AM, J. Bakshi <j.bakshi@unlimitedmail.org> wrote:
>> >  it works well.  But if I try to add command substitution ( with in back-qoutes ) to dynamically collect the user name , it stops working. The rule is like
>> >
>> > ```````````````
>> >  ACTION="add", SUBSYSTEM="input", ENV{ID_CLASS}="mouse", ENV{DISPLAY}=":0.0", ENV{XAUTHORITY}="/home/user1/.Xauthority"  RUN+="/bin/su  `ps aux | grep startx | grep '/bin/sh' | awk '{print $1}'`  -c "DISPLAY=:0.0 notify-send "test"  "
>> >  ``````````````````````````
>> >
>>
>> I do not think udev is using shell to start external commands. You
>> will need to use something like
>>
>> RUN+="/bin/sh -c '...'"
>>
>> Quoting will quickly become unmanageable I am afraid :)
>
> Yes, I have tried with that but no success. I used
>
> RUN+="/bin/sh -c '/bin/su user1 -c 'DISPLAY=:0.0 notify-send test''"
>
> and no luck.

Why not just create a script that does what you want and have udev RUN
that? Otherwise, you'll need to work out escaping the multiple levels
of quotes with \.

--
Dan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: problem executing command substitution from udev rules
  2010-11-02  6:46 problem executing command substitution from udev rules J. Bakshi
                   ` (2 preceding siblings ...)
  2010-11-03 13:17 ` Dan Nicholson
@ 2010-11-03 15:50 ` J. Bakshi
  3 siblings, 0 replies; 5+ messages in thread
From: J. Bakshi @ 2010-11-03 15:50 UTC (permalink / raw)
  To: linux-hotplug

On Wed, 3 Nov 2010 06:17:55 -0700
Dan Nicholson <dbn.lists@gmail.com> wrote:

> 
> Why not just create a script that does what you want and have udev RUN
> that? Otherwise, you'll need to work out escaping the multiple levels
> of quotes with \.
> 

Thank Dan, I have already made a script and call it from udev rule. Though I'll also give a try with "\"

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-11-03 15:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-02  6:46 problem executing command substitution from udev rules J. Bakshi
2010-11-02  9:51 ` Andrey Borzenkov
2010-11-02 11:49 ` J. Bakshi
2010-11-03 13:17 ` Dan Nicholson
2010-11-03 15:50 ` J. Bakshi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.