Wi-Fi 카드가 연결되어있을 때 자동 실행 스크립트 (udev) (usb) UDEV [1017.733002] remove

udev무선 카드가 연결되어있을 때 데비안 시스템에서 bash 스크립트를 실행 하려고했습니다 .

지금 까지이 파일을 만들었습니다 /etc/udev/rules.d/wifi-detect.rules.

ACTION=="add", ATTRS{idVendor}=="0cf3", ATTRS{idProduct}=="9271", RUN+="/root/test.sh"

그리고 지금 test.sh은이 내용을 작동 시키려고합니다 .

#!/bin/bash
/bin/echo "test!" > /test.txt

그러나 어떤 이유로 든 무선 카드를 연결할 때 아무 일도 일어나지 않으며 test.txt파일이 생성 되지 않습니다 .

lsusb카드에 내 :

Bus 001 Device 015: ID 0cf3:9271 Atheros Communications, Inc. AR9271 802.11n

udevadm monitor –env이것을 실행 하면 카드를 연결할 때 발생합니다.

KERNEL[1017.642278] add      /devices/platform/bcm2708_usb/usb1/1-1/1-1.3 (usb)
KERNEL[1017.644676] add      /devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3:1.0 (usb)
KERNEL[1017.645035] add      /devices/platform/bcm2708_usb/usb1/1-1/1-1.3/firmware/1-1.3 (firmware)
KERNEL[1017.708056] remove   /devices/platform/bcm2708_usb/usb1/1-1/1-1.3/firmware/1-1.3 (firmware)
UDEV  [1017.714772] add      /devices/platform/bcm2708_usb/usb1/1-1/1-1.3 (usb)
UDEV  [1017.733002] remove   /devices/platform/bcm2708_usb/usb1/1-1/1-1.3/firmware/1-1.3 (firmware)
UDEV  [1017.772669] add      /devices/platform/bcm2708_usb/usb1/1-1/1-1.3/firmware/1-1.3 (firmware)
UDEV  [1017.798707] add      /devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3:1.0 (usb)
KERNEL[1018.456804] add      /devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3:1.0/ieee80211/phy8 (ieee80211)
KERNEL[1018.465994] add      /devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3:1.0/net/wlan0 (net)
KERNEL[1018.479878] add      /devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3:1.0/leds/ath9k_htc-phy8 (leds)
KERNEL[1018.483074] add      /devices/platform/bcm2708_usb/usb1/1-1/1-1.3/usb_device/usbdev1.20 (usb_device)
UDEV  [1018.600456] add      /devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3:1.0/leds/ath9k_htc-phy8 (leds)
UDEV  [1018.604376] add      /devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3:1.0/ieee80211/phy8 (ieee80211)
UDEV  [1018.626243] add      /devices/platform/bcm2708_usb/usb1/1-1/1-1.3/usb_device/usbdev1.20 (usb_device)
KERNEL[1018.659318] move     /devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3:1.0/net/wlan1 (net)
UDEV  [1018.758843] add      /devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3:1.0/net/wlan1 (net)
UDEV  [1018.932207] move     /devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3:1.0/net/wlan1 (net)

많은 예제를 시도했지만 작동시킬 수 없습니다. 누군가가 나를 도울 수 있기를 바랍니다.) 감사합니다!


편집하다:

일을 단순화하기 위해 규칙을 다음과 같이 변경했습니다.

ACTION=="add", ATTRS{idVendor}=="0cf3", ATTRS{idProduct}=="9271", RUN+="/bin/echo 'test' > /test.txt"

udevadm control --log-priority=info@ user1146332가 제안한대로 설정 하고이 흥미로운 로그를 얻었습니다.

Sep  9 16:27:53 iklive-rpi1 udevd[1537]: RUN '/bin/echo 'test' > /test.txt' /etc/udev/rules.d/wifi-detect.rules:1
Sep  9 16:27:53 iklive-rpi1 udevd[1544]: starting 'firmware.agent'
Sep  9 16:27:53 iklive-rpi1 udevd[126]: seq 663 queued, 'remove' 'firmware'
Sep  9 16:27:53 iklive-rpi1 udevd[126]: seq 663 forked new worker [1547]
Sep  9 16:27:53 iklive-rpi1 udevd[1537]: 'firmware.agent' [1544] exit with return code 0
Sep  9 16:27:53 iklive-rpi1 udevd[1548]: starting '/bin/echo 'test' > /test.txt'
Sep  9 16:27:53 iklive-rpi1 udevd[1547]: seq 663 running
Sep  9 16:27:53 iklive-rpi1 udevd[1547]: no db file to read /run/udev/data/+firmware:1-1.3.4: No such file or directory
Sep  9 16:27:53 iklive-rpi1 udevd[1547]: passed -1 bytes to netlink monitor 0x1af5ee0
Sep  9 16:27:53 iklive-rpi1 udevd[126]: seq 663 done with 0
Sep  9 16:27:53 iklive-rpi1 udevd[1547]: seq 663 processed with 0
Sep  9 16:27:53 iklive-rpi1 udevd[1537]: '/bin/echo 'test' > /test.txt'(out) 'test > /test.txt'
Sep  9 16:27:53 iklive-rpi1 udevd[1537]: '/bin/echo 'test' > /test.txt' [1548] exit with return code 0

그렇다면 … return code 0성공적인 완료를위한 종료 코드가 아닌가요? 그렇다면 왜 시스템에 파일이 없습니까?


편집 2 :

@htor의 팁을 사용 하여이 작업을 수행했습니다. 나의 현재 규칙 :

ACTION=="add", ATTRS{idVendor}=="0cf3", ATTRS{idProduct}=="9271", RUN+="/bin/sh -c '/bin/echo test >> /test.txt'"

그러나 어떤 이유로 명령이 8 번 실행되는 것을 피할 수 있습니까? 무선 카드 드라이버를로드 할 때 실제로 카드를 마운트 해제하고 마운트해야하기 때문에 발생하는 것 같습니다. 팁?



답변

나는 한 비슷한 문제 동안 전 및 솔루션은 변화하는 것이었다 RUN+=에 대한 부분 RUN+="sh -c '/root/test.sh'". 이제 규칙이 명령이 아닌 스크립트를 호출하기 때문에이 경우에 필요한지 모르겠습니다.

또 다른 관찰 : 문자열 !에서를 제거 "test!"하거나 큰 따옴표를 작은 따옴표로 바꾸십시오. 뱅 !은 쉘에서 특별한 의미로 인해 문제를 일으킬 수 있으며 큰 따옴표는 그 의미를 유지합니다.


답변

내 조언은 로깅 우선 순위를 설정하는 것 udev에서 errinfo

 udevadm control --log-priority=info

더 많은 정보를 보려면로 설정하십시오 debug. 지금 당신은 무엇을 매우 상세한 정보를 찾을 수 있습니다 udev에서 한 /var/log/daemon.log(데비안 관련 시스템에 적어도 참조). 일반적으로 많은 추적 오류를 돕습니다.

이것은 아마도 문제를 해결할 수있는 htor의 대답에 대한 보완 일뿐입니다.


답변