简体   繁体   中英

run program when usb connected to raspberry pi

I'm trying to run a program when I plug USB to my Raspberry Pi 3 model B.

I referenced below two https://hackaday.com/2009/09/18/how-to-write-udev-rules/ https://unix.stackexchange.com/questions/65891/how-to-execute-a-shellscript-when-i-plug-in-a-usb-device

  1. write a *.rules file in /etc/udev/rules.d/ directory
sudo nano /etc/udev/rules.d/81-usb.rules
  1. fill with
KERNEL=="sda1", RUN+="echo Hello World > /home/pi/hello.txt"
  1. restart udev
sudo /etc/init.d/udev restart

I almost tried every variation, rebooted a lot, just in case I'm missing something. But nothing works.

Thanks for reading.

Thanks stark. Anyway I'm answering my own Question.

I changed it from

KERNEL=="sda1", RUN+="echo Hello World > /home/pi/hello.txt"

to

KERNEL=="sda1", RUN+="/home/pi/test.sh"

also did

chmod +x /home/pi/test.sh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM