1

So I'm currently trying to get udev to do some things (start airmon-ng) after I've connected a specific USB wifi network card. But I am having troubles getting inline scripts to work. The problem can be reproduced using the following simple example:

Create the following executable script /test.sh:

#!/bin/sh
echo hello > /tmp/test.txt

Create the following file /etc/udev/rules.d/85-auto-monitor.rules:

# This works:
ACTION=="move", KERNEL=="wlx8416f91a5ed3", RUN+="/test.sh"

# This does not work:
# ACTION=="move", KERNEL=="wlx8416f91a5ed3", RUN+="sh -c 'echo hello > /tmp/test.txt'"

Use the following command to reload the .rules file:

sudo udevadm control --reload 

I simply can't understand why the external script works but not the inline one. The inline scripts works if I run it in my terminal.

2

1 Answer 1

1

From man 7 udev:

RUN{type}

  Add a program to the list of programs to be executed after processing all the rules for a specific event, depending on "type":

"program"

   Execute an external program specified as the assigned value. If no absolute path is given, the program is expected to live in /usr/lib/udev; otherwise, the absolute path must be specified.

   This is the default if no type is specified.

"builtin"

   As program, but use one of the built-in programs rather than an external one.

So, in your example your must use the absolute path to sh as Alex P. mentioned:
RUN+="/bin/sh -c 'echo hello > /tmp/test.txt'"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .