Неоднократно выполняйте команду удара, в то время как нет никакого вывода от другого процесса

Необходимо гарантировать следующее:

  • Пути в RUN команда должна быть абсолютной
  • Файл должен быть исполняемым файлом
  • PATH среда ограничена в рамках выполнения Вас команда

Сначала добавьте этот файл сценария к /lib/udev/touch.sh

vim /lib/udev/touch.sh

в той записи файла:

#!/bin/bash
touch /tmp/test

сделайте это исполняемым файлом:

chmod +x /lib/udev/touch.sh

и измените свой файл правил на:

ACTION=="add", SUBSYSTEMS=="usb", RUN+="/lib/udev/touch.sh"

перезагрузите свои правила udev

udevadm control --reload-rules

Это прочитает Ваши правила в /lib/udev/rules.d/* снова. Изменения не будут применяться до сих пор.

Обратите внимание, что udev выполняет Ваш сценарий с уменьшенным PATH среда. Необходимо удостовериться, чтобы к любому двоичному файлу, который это не в настроенных путях, получили доступ с полным путем. Вы могли также расшириться PATH среда в рамках Вашего сценария.

Проверьте то, что путь определяется путем входа set вывод к файлу журнала из Вашего сценария обертки:

set >>/tmp/udev-env-test

Это могло бы быть похожим на это:

PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
3
07.03.2015, 18:02
2 ответа
sudo fs_usage -w | while true; do
    if read -rt5 && [[ $REPLY =~ objectpattern ]]; then
        # Some output happened in the last 5 seconds that matches object pattern
        :
    else 
        touch objectfile
    fi
done

, конечно, с использованием READ -T означает, что есть возможность того, что есть какой-то выход не Соответствие ObjectPattern ; Если это произойдет, файл будет затронут. Если вы хотите избежать этого, мы должны получить немного более изощренного.

timeout=5
sudo fs_usage -w | while true; do
    (( mark = SECONDS + timeout ))
    if !read -rt$timeout; then
        touch objectfile
        timeout=5
    elif ![[ $REPLY =~ objectpattern ]]; then
        # Some output happened within timeout seconds that does _not_ match.
        # Reduce timeout by the elapsed time.
        (( timeout = mark - SECONDS ))
        if (( timeout < 1 )); then
            touch objectfile
            timeout=5
        fi
    else
        timeout=5
    fi
done
2
27.01.2020, 21:27

Если я вас правильно понимаю, то, вероятно, вы хотите сделать:

sh -c '{ fsusage             #your command runs (indefintely?)
         kill -PIPE "$$"     #but when it completes, so does this shell
       } >&3 &               #backgrounded and all stdout writes to pipe
       while sleep 5         #meanwhile, every 5 seconds a loop prints
       do    echo            #a blank line w/ echo
       done' 3>&1 |          #also to a pipe, read by an unbuffered (GNU) sed
sed -u '
### if first input line, insert shell init to stdout
### for seds [aic] commands continue newlines w/ \escapes
### and otherwise \escape only all other backslashes
1i\
convenience_func(){ : this is a function  \\\
                      declared in target  \\\
                      shell and can be    \\\
                      called from sed.; }
### if line matches object change it to command
/object/c\
# this is an actual command sent to a shell for each match
### this is just a comment - note the \escaped newlines above                    
### delete all other nonblank lines; change all blanks
/./d;c\
# this is a command sent to a shell every ~5 seconds
' | sh -s -- This is the target shell and these are its   \
             positional parameters. These can be referred \
             to in sed\'s output like '"$1"' or '"$@"' as \
             an array. They can even be passed along to   \
             'convenience_func()' as arguments.

Около 90% вышеперечисленного состоит из комментариев. В основном это может быть отварно до ...

sh -c '(fsusage;kill "$$") >&3 &
       while sleep 5; do echo; done
' 3>&1| 
sed -nue '/pattern/c\' -e 'echo match
          /./!c\'      -e 'touch -- "$1"
' | sh -s -- filename
0
27.01.2020, 21:27

Теги

Похожие вопросы