udevルールに問題があります

udevルールに問題があります

Bluetoothキーボードを接続するときに.shスクリプトを実行できません。

以下のudevルールを使用しています。

ACTION=="add", SUBSYSTEM=="bluetooth", RUN+="./scripts/icleverkeybindings.sh" 

キーボードを接続してもスクリプトがアクティブにならないようです。また、「./scripts/iceverkeybindings.sh」、「/bin/bash /scripts/iceverkeybindings.sh」、「sh /scripts/iceverkeybindings.sh」も試しました。このスクリプトがなぜアクティブにならないのか理解できません。

代わりに、次のudevルールを使用すると、

ACTION=="add", SUBSYSTEM=="bluetooth", RUN+="/bin/mkdir /home/joe/tempfolder" 

その後、キーボードを接続すると、/home/joe/tempfolderフォルダが作成されます。

/etc/udev/rules.d/50-addiceverkeybindings.shにルールを保存しました。権限などは次のとおりです。 -rw-r--r-- 1 joe root 80 Aug 11 19:53 50-addiceverkeyboard.rules。

私が実行したいスクリプトは次のとおりです。

#!/bin/bash

sleep 1
cheese

remote_id=$(
    xinput list |
    sed -n 's/.*iClever IC-BK06 Keyboard  .*id=\([0-9]*\).*keyboard.*/\1/p'
)
[ "$remote_id" ] || exit

xkbcomp -i $remote_id /scripts/icleverlayout.xkb $DISPLAY

ls -la は -rwxr-xr-x 1 joe root 222 Aug 11 20:00 iceverkeybindings.sh を提供します。

ターミナルで単に/scripts/iceverkeybindings.shを呼び出すと正常に動作します。

スクリプトは私のキーボードのキーバインディングを変更し、xinputがキーボードがあることを知る前にスクリプトが呼び出される場合に備えて一時停止を追加し、確実に呼び出されるかどうかを確認するためにチーズを追加しました.

スクリプトが呼び出されるようにルールを変更する方法を教えてくれる人はいますか?

ありがとう

編集:明確にするために/ scripts /フォルダを作成したので、/ scripts / iceverkeybindings.shは絶対ファイルパスです。

ベストアンサー1

それは言うman 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 /lib/udev; otherwise, the absolute
           path must be specified.

確認できる他のログは何ですかudev

Aug 11 21:57:43 ja-VirtualBox systemd-udevd[2998]: failed to execute '/lib/udev/./scripts/icleverkeybindings.sh' './scripts/icleverkeybindings.sh': No such file or directory

またはシステム化されていないシステム:

[769712.027218] udevd[13015]: failed to execute '/lib/udev/./scripts/icleverkeybindings.sh' './scripts/icleverkeybindings.sh': No such file or directory

しかし、 icleverkeybindings.shudevルールでは、次のように絶対パスを渡す必要があります。

ACTION=="add", SUBSYSTEM=="bluetooth", RUN+="/path/to/icleverkeybindings.sh"

または、udevルールにファイル名をicleverkeybindings.sh入力して使用します。/lib/udev

ACTION=="add", SUBSYSTEM=="bluetooth", RUN+="icleverkeybindings.sh"

icleverkeybindings.sh どちらの場合も、実行可能ビットが設定されていることを確認する必要があります。そうでない場合:

Aug 11 22:07:49 ja-VirtualBox systemd-udevd[3345]: failed to execute '/lib/udev/icleverkeybindings.sh' 'icleverkeybindings.sh': Permission denied
Aug 11 22:07:49 ja-VirtualBox systemd-udevd[3325]: Process 'icleverkeybindings.sh' failed with exit code 2.

おすすめ記事