The udev rule runs a bash script several times

I created a udev rule to execute a bash script after inserting a USB device

SUBSYSTEMS=="usb", ATTRS{serial}=="00000000", SYMLINK+="Kingston", RUN+="/bin/flashled.sh"

However, the script is run several times, and not once, I assume that everything has been found to failure. I tried putting dream 10 in script and fi, but that doesn't make any difference.

+4
source share
1 answer

This is not a solution, but a workaround:
One way (simple) is to start your script "/bin/flashled.sh", like this

#!/bin/bash
#this file is /bin/flashled.sh

#let exit if another instance is already running
if [[ $(pgrep -c "$0" ) -gt 1 ]]; then exit ;fi

... ... ...

However, this may be in some cases, the border is slightly subject to the conditions of the race (bash is a little slower, so there is no way to make sure that this will always work), but it can work fine in your case.

( , ) "/bin/flashled.sh" :

#!/bin/bash
#this file is /bin/flashled.sh
#write in your /etc/rc.local: /bin/flashled.sh & ; disown
#or let it start by init.    

while :
do
    kill -SIGSTOP $$ # halt and wait
    ... ...          # your commands here
    sleep $TIME      # choose your own value here instead of $TIME
done

(,/etc/rc.local), ... , "" ( ), $TIME

udev :

SUBSYSTEMS=="usb", ATTRS{serial}=="00000000", SYMLINK+="Kingston", RUN+="/usr/bin/pkill -SIGCONT flashled.sh"
0

All Articles